[glib] gmem: Clarify that a NULL check is not needed before calling g_free()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gmem: Clarify that a NULL check is not needed before calling g_free()
- Date: Tue, 3 Mar 2015 18:41:09 +0000 (UTC)
commit 18c9a4e17a74b1707b8a17779e13956e151edc27
Author: Philip Withnall <philip withnall collabora co uk>
Date: Fri Dec 19 19:01:06 2014 +0000
gmem: Clarify that a NULL check is not needed before calling g_free()
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 files 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.
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]