[glib/glib-2-28] g_array_free, g_ptr_array_free: decrement refcount if not the last ref
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-28] g_array_free, g_ptr_array_free: decrement refcount if not the last ref
- Date: Mon, 16 Jan 2012 18:33:08 +0000 (UTC)
commit 18f003303a073104ccf8803657312a15410eae1b
Author: Simon McVittie <simon mcvittie collabora co uk>
Date: Wed Dec 14 16:56:15 2011 +0000
g_array_free, g_ptr_array_free: decrement refcount if not the last ref
foo_free is conceptually "worth" one unref; not decrementing the
refcount here means the GArray or GPtrArray wrapper (but not its
contents) would leak in the following call sequence:
p = g_ptr_array_new ();
g_ptr_array_ref (p);
g_ptr_array_free (p, TRUE);
g_ptr_array_unref (p);
Signed-off-by: Simon McVittie <simon mcvittie collabora co uk>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=666113
Reviewed-by: Emmanuele Bassi <ebassi linux intel com>
glib/garray.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/glib/garray.c b/glib/garray.c
index b602674..02d09ba 100644
--- a/glib/garray.c
+++ b/glib/garray.c
@@ -303,7 +303,7 @@ g_array_free (GArray *farray,
flags = (free_segment ? FREE_SEGMENT : 0);
/* if others are holding a reference, preserve the wrapper but do free/return the data */
- if (g_atomic_int_get (&array->ref_count) > 1)
+ if (!g_atomic_int_dec_and_test (&array->ref_count))
flags |= PRESERVE_WRAPPER;
return array_free (array, flags);
@@ -949,7 +949,7 @@ g_ptr_array_free (GPtrArray *farray,
flags = (free_segment ? FREE_SEGMENT : 0);
/* if others are holding a reference, preserve the wrapper but do free/return the data */
- if (g_atomic_int_get (&array->ref_count) > 1)
+ if (!g_atomic_int_dec_and_test (&array->ref_count))
flags |= PRESERVE_WRAPPER;
return ptr_array_free (farray, flags);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]