quick question
Can you use the free () function without calling malloc first ??
e.
void someFunc( void ) { char str[6] = {"Hello"}; //some processing here .... free(str); }
I cannot compile errors, but does this work or is everything correct?
Thank,
This is not entirely correct:
char str[6]
malloc() , . , . , , . str, stack , , .
str
non-malloc'd Segfault. :
#include <stdlib.h> int main() { char str[6] = {"Hello"}; free(str); }
$gcc test.c -o test
$./test
free() , . , malloc() calloc(), , , .
, undefined. , . .
, . . , , , malloc() void * free() void *; , , . , , - , . , ; , , , valgrind, , .
The function free(3)takes a parameter void *, so you can pass it any pointer without a compile-time error. But bad things will happen if the pointer was not originally returned malloc(3)and never previously returned to free(3).
free(3)
void *
malloc(3)
Source: https://habr.com/ru/post/1773335/More articles:DOM node.textContent parsing and replacing - domanalyze content for a keyword to appear inside h1, h2 and h3 headers - phpCombining jQuery with PHP - jqueryJQuery user interface buttons and anchor tags - jqueryМышление Sphinx для поиска по всей программе: фильтрация по атрибуту, который существует только в некоторых моделях - searchHow to run Perl Script from Cmd without typing "perl" before the Script path? - windowsHow to learn a package in python - pythonQuestion about org.apache.commons.dbcp.BasicDataSource - apache-commonsSkybox OpenGL ES iPhone and iPad - iphoneHow can I allocate a week in Oracle using a custom first day of the week? - oracleAll Articles