For example:
char * myString = malloc(sizeof(char)*STRING_BUFFER_SIZE);
free(myString);
free(myString);
Are there any adverse side effects
Here's the chapter and verse.
If the argument [to the
free
function] does not match a pointer earlier returned by thecalloc
,malloc
, orrealloc
function, or if the space has been deallocated by a call tofree
orrealloc
, the behavior is undefined. (ISO 9899:1999 - Programming languages — C, Section 7.20.3.2)
Not so clever. Google for double free vulnerabilities. Set your pointer to NULL
after freeing to avoid such bugs.