|
|
|
|
|
by bch
4519 days ago
|
|
The article says two different things about how free() works: 1. In case of NULL pointer free does no action.
2. In "double free corruption" section, it says "Could be caused by calling free with pointer, which is [..] NULL pointer"
So: which is it? Otherwise, there's no point in the NULL/assert() dance, you can freely free() with impunity: struct foo *a, *b, *c;
a=NULL; b=NULL; c=NULL;
a=malloc(sizeof *a);
b=malloc(sizeof *b);
c=malloc(sizeof *c);
if(!(a && b && c)) {free(a); free(b); free(c); return 1;}
|
|
Calling free() on NULL is a no-op.