[glib] GVariant: fix some refcounting issues



commit 118d59ba15324b49ab9f8b61332364148102d3fd
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Mar 5 06:09:38 2010 -0500

    GVariant: fix some refcounting issues

 glib/gvariant.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/glib/gvariant.c b/glib/gvariant.c
index 00a16da..4cb6220 100644
--- a/glib/gvariant.c
+++ b/glib/gvariant.c
@@ -676,6 +676,8 @@ g_variant_new_variant (GVariant *value)
 {
   g_return_val_if_fail (value != NULL, NULL);
 
+  g_variant_ref_sink (value);
+
   return g_variant_new_from_children (G_VARIANT_TYPE_VARIANT,
                                       g_memdup (&value, sizeof value),
                                       1, g_variant_is_trusted (value));
@@ -1172,11 +1174,11 @@ g_variant_new_strv (const gchar * const *strv,
   g_return_val_if_fail (length == 0 || strv != NULL, NULL);
 
   if (length < 0)
-    for (length = 0; strv[length]; length++);
+    length = g_strv_length ((gchar **) strv);
 
   strings = g_new (GVariant *, length);
   for (i = 0; i < length; i++)
-    strings[i] = g_variant_new_string (strv[i]);
+    strings[i] = g_variant_ref_sink (g_variant_new_string (strv[i]));
 
   return g_variant_new_from_children (G_VARIANT_TYPE ("as"),
                                       strings, length, TRUE);
@@ -1561,6 +1563,7 @@ g_variant_print_string (GVariant *value,
             element = g_variant_get_child_value (value, i);
             g_variant_print_string (element, string, type_annotate);
             g_string_append (string, ", ");
+            g_variant_unref (element);
           }
 
         /* for >1 item:  remove final ", "



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]