c - Does freeing an uninitialized pointer result in undefined behavior? -
if have pointer not initialized and, mistake, try free it, going result in undefined behavior?
like:
int main(void){ char *string; free(string); return 0; }
does freeing uninitialized pointer result in undefined behavior?
yes.
however, freeing null pointer well-defined.
from c99 standard:
the
free
function causes space pointedptr
deallocated, is, made available further allocation. ifptr
null pointer, no action occurs. otherwise, if argument not match pointer earlier returnedcalloc
,malloc
, orrealloc
function, or if space has been deallocated callfree
orrealloc
, behavior undefined.
Comments
Post a Comment