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
freefunction causes space pointedptrdeallocated, is, made available further allocation. ifptrnull pointer, no action occurs. otherwise, if argument not match pointer earlier returnedcalloc,malloc, orreallocfunction, or if space has been deallocated callfreeorrealloc, behavior undefined.
Comments
Post a Comment