Quoting the C standard, 7.20.3.2/2 from ISO-IEC 9899:
void free(void *ptr);
If ptr
is a null pointer, no action occurs.
Don't check for NULL
, it only adds more dummy code to read and is thus a bad practice.
However, you must always check for NULL
pointers when using malloc
& co. In that case NULL
mean that something went wrong, most likely that no memory was available.