I often write " if (p) free(p) ", even if I know that it is not necessary.
I partially blame myself because I found out that in the old days when free(NULL) would be segfault, and I still feel uncomfortable without doing it.
But I also blame the C standard for not being consistent. Would fclose (NULL), for example, be well defined, I would not have problems in writing:
free(p); fclose(f);
This is what happens very often when cleaning things. Unfortunately, it seems strange to me to write
free(p); if (f) fclose(f);
and I end up being
if (p) free(p); if (f) fclose(f);
I know this is not a reasonable reason, but my case :)
Remo.D Dec 16 '09 at 11:41 2009-12-16 11:41
source share