Suppose I came across an instance in a program where I would either free the NULL pointer, or first check if it was NULL and skip the call to the free() function.
Would it be more efficient to just free the NULL pointer? I searched a bit and, apparently, for C89 post implementations, it is harmless to free the NULL pointer, so the solution comes down to efficiency.
My presumption is that when you call free() can potentially have quite a bit of overhead. Thus, perhaps a simple logical check before calling the free() function is absolutely necessary.
tl; dr version,
What happens internally when a call to free() is called, which can make it more or less efficient, to first check if the pointer is NULL before being released?
source share