[glib] GVariant: add preconditions to ref. counting functions
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GVariant: add preconditions to ref. counting functions
- Date: Fri, 2 Dec 2011 10:23:29 +0000 (UTC)
commit 22da18fa706c685da015c9b9a786d810270b3a5f
Author: Philip Withnall <philip tecnocode co uk>
Date: Wed Nov 30 10:20:13 2011 +0000
GVariant: add preconditions to ref. counting functions
These prevent GVariants from accidentally being brought back to life after
being freed, and should make it easier to track down ref. counting issues.
Closes: bgo#665184
glib/gvariant-core.c | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/glib/gvariant-core.c b/glib/gvariant-core.c
index 436d4bf..fdbe034 100644
--- a/glib/gvariant-core.c
+++ b/glib/gvariant-core.c
@@ -619,6 +619,9 @@ g_variant_is_trusted (GVariant *value)
void
g_variant_unref (GVariant *value)
{
+ g_return_if_fail (value != NULL);
+ g_return_if_fail (value->ref_count > 0);
+
if (g_atomic_int_dec_and_test (&value->ref_count))
{
if G_UNLIKELY (value->state & STATE_LOCKED)
@@ -652,6 +655,9 @@ g_variant_unref (GVariant *value)
GVariant *
g_variant_ref (GVariant *value)
{
+ g_return_val_if_fail (value != NULL, NULL);
+ g_return_val_if_fail (value->ref_count > 0, NULL);
+
g_atomic_int_inc (&value->ref_count);
return value;
@@ -691,6 +697,9 @@ g_variant_ref (GVariant *value)
GVariant *
g_variant_ref_sink (GVariant *value)
{
+ g_return_val_if_fail (value != NULL, NULL);
+ g_return_val_if_fail (value->ref_count > 0, NULL);
+
g_variant_lock (value);
if (~value->state & STATE_FLOATING)
@@ -746,6 +755,7 @@ GVariant *
g_variant_take_ref (GVariant *value)
{
g_return_val_if_fail (value != NULL, NULL);
+ g_return_val_if_fail (value->ref_count > 0, NULL);
g_atomic_int_and (&value->state, ~STATE_FLOATING);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]