...
Code Block |
---|
char *p = /* initialize, may or may not be NULL */ if (p || (p = (char *) malloc(BUF_SIZE)) ) { /* do stuff with p */ free(p); p) = NULL; } else { /* handle malloc() error */ return; } |
Since malloc()
is only called if p
is NULL when entering the if
clause, free()
might be called with a pointer to local data not allocated by malloc()
(see MEM34-C. Only free memory allocated dynamically). This is partially due to the uncertainty of whether malloc()
is actually called or not.
...