-Some implementations crash upon attempts to free or realloc the null
-pointer. Thus if mem might be null, you need to write
+ if (P)
+ free (P);
+
+It is better to avoid the test.[*]
+Instead, simply free P, regardless of whether it is NULL.
+
+[*] However, if your profiling exposes a test like this in a
+performance-critical loop, say where P is nearly always NULL, and
+the cost of calling free on a NULL pointer would be prohibitively
+high, consider using __builtin_expect, e.g., like this:
+
+ if (__builtin_expect (ptr != NULL, 0))
+ free (ptr);