It may be supported by the standard now, but that doesn't mean it's supported by all compilers on all systems. And it didn't used to be supported by the standard.
I remember back in the day having all kinds of problems with programs crashing when I tried to free a NULL pointer. if(p) free(p);
Would often be all it took to fix the crash. Of course, it didn't solve the source of the bad pointer, just prevented the program from crashing on error.
These days free(NULL)
is widely supported, and the if(p)
is no longer necessary. Even if you do find your program crashing on invalid pointer data, I'd say let it. Invalid pointers indicate a problem that won't be fixed by simply not trying to free them. Better to find and fix the source.