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

mod rewrite - Using "?" when rewriting the URL -

.htaccess: Transfer name to index.php if not directory public -

Admob integration with pygame in android -