c - Free function not working -
i have following c code.
#include <stdio.h> #include <stdlib.h> int main() { while (1) { int *test = malloc(sizeof(*test)); test = 500; free(test); } return 0; }
the free function not seem work allocated memory grows 2gb within few seconds. problem?
you can free
pointer return of malloc
.
in writing test = 500
, you've changed memory location pointed test
. trying free undefined behaviour.
to assign value allocated integer, derefence it: *test = 500
;
Comments
Post a Comment