Take this code, for example:
int *doSomething(void) { int *something = malloc(sizeof(int)); return something; } int main() { int *point = doSomething(); //code does something... free(point); }
I am wondering if I need to free the memory allocated in doSomething(), for example, after return something;what do I need to do free(something);? Or does execution free(point);also clear something? Or maybe I need to do free(something);in a function mainbefore the code ends?
doSomething()
return something;
free(something);
free(point);
something
main
, doSomething(), free(point) malloc() ed doSomething() , ( ), free() * alloc().
free(point)
malloc()
free()
alloc()
point main(), , point != NULL.
point
main()
point != NULL
. , , , , , .
, malloc free. , , free, malloc. ( main), , OS . free , , , .
malloc
free
, , :
int *p = malloc(...); /* do some stuff */ p = malloc(...);
, malloc, ( , ).
Source: https://habr.com/ru/post/1628633/More articles:Visual Studio Code Format Code not working on Mac OS X (El Capitan) - visual-studio-codedyld: library not loaded: @ rpath / libswiftCore.dylib - iosError getting value or text in java script - javascriptRanger File Manager - Accessing a Remote Server? - consoleHow to resolve RSpec failure warning about new wait syntax? - ruby-on-railsIs a sequence diagram for use in UML or are we drawing it for the system as a whole? - umlI logged google into the ios app. Now, how can I check if the user is registered, and if not, return him to the login page using Swift? - iosHow to use OBJLoader and MTLLoader in THREE.js r74 and later - three.jsHow to determine the arguments that will be passed to a particular IL method call in Mono.Cecil - c #JavaScript precision - javascriptAll Articles