From 18c9a4e17a74b1707b8a17779e13956e151edc27 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 19 Dec 2014 19:01:06 +0000 Subject: [PATCH] gmem: Clarify that a NULL check is not needed before calling g_free() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/glib/gmem.c b/glib/gmem.c index 6a108ee..dd031ba 100644 --- a/glib/gmem.c +++ b/glib/gmem.c @@ -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. */ -- 2.7.4