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 pointed ptr deallocated, is, made available further allocation. if ptr null pointer, no action occurs. otherwise, if argument not match pointer earlier returned calloc, malloc, or realloc function, or if space has been deallocated call free or realloc, behavior undefined.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -