c - Dynamically allocate and free memory in local functions -
consider following function:
void free_or_not ( int count ) { int ; int *ip = malloc ( count * sizeof ( int ) ) ; ( = 0 ; < count ; ++ ) ip[i] = ; ( = 0 ; < count ; ++ ) printf ( "%d\n" , ip[i] ) ; free ( ip ) ; }
will cause memory leak if don't call free()
inside free_or_not()
?
yes,when function finishes, lose pointer allocated memory free() it.
Comments
Post a Comment