gmem: Clarify that a NULL check is not needed before calling g_free()
authorPhilip Withnall <philip.withnall@collabora.co.uk>
Fri, 19 Dec 2014 19:01:06 +0000 (19:01 +0000)
committerPhilip Withnall <philip.withnall@collabora.co.uk>
Tue, 3 Mar 2015 18:40:33 +0000 (18:40 +0000)
It was documented before, but wasn’t especially clear. Doing
    if (X)
        g_free (X);
is apparently quite a pervasive real-world anti-pattern, so perhaps it
could be documented more explicitly.

https://bugzilla.gnome.org/show_bug.cgi?id=741779

glib/gmem.c

index 6a108ee..dd031ba 100644 (file)
@@ -181,7 +181,9 @@ g_realloc (gpointer mem,
  * @mem: (allow-none): the memory to free
  * 
  * Frees the memory pointed to by @mem.
- * If @mem is %NULL it simply returns.
+ *
+ * If @mem is %NULL it simply returns, so there is no need to check @mem
+ * against %NULL before calling this function.
  */
 void
 g_free (gpointer mem)
@@ -281,7 +283,9 @@ g_try_malloc0 (gsize n_bytes)
  * 
  * Attempts to realloc @mem to a new size, @n_bytes, and returns %NULL
  * on failure. Contrast with g_realloc(), which aborts the program
- * on failure. If @mem is %NULL, behaves the same as g_try_malloc().
+ * on failure.
+ *
+ * If @mem is %NULL, behaves the same as g_try_malloc().
  * 
  * Returns: the allocated memory, or %NULL.
  */