[glib] Plug a mem leak



commit 0a7c0ac74bd55d06265e9441c5728119adc254ab
Author: Christian Persch <chpe gnome org>
Date:   Fri May 14 18:08:29 2010 -0400

    Plug a mem leak
    
    This code leaked the return value of g_variant_get_child_value();
    use g_variant_get() instead and free the iter when done.

 gio/gdbusproxy.c |   22 +++++++++-------------
 1 files changed, 9 insertions(+), 13 deletions(-)
---
diff --git a/gio/gdbusproxy.c b/gio/gdbusproxy.c
index 53ef06e..51cb5f2 100644
--- a/gio/gdbusproxy.c
+++ b/gio/gdbusproxy.c
@@ -797,8 +797,9 @@ static void
 process_get_all_reply (GDBusProxy *proxy,
                        GVariant   *result)
 {
-  GVariantIter iter;
-  GVariant *item;
+  GVariantIter *iter;
+  gchar *key;
+  GVariant *value;
 
   if (strcmp (g_variant_get_type_string (result), "(a{sv})") != 0)
     {
@@ -807,22 +808,17 @@ process_get_all_reply (GDBusProxy *proxy,
       goto out;
     }
 
-  g_variant_iter_init (&iter, g_variant_get_child_value (result, 0));
-  while ((item = g_variant_iter_next_value (&iter)) != NULL)
+  g_variant_get (result, "(a{sv})", &iter);
+  while (g_variant_iter_next (iter, "{sv}", &key, &value))
     {
-      gchar *key;
-      GVariant *value;
-
-      g_variant_get (item,
-                     "{sv}",
-                     &key,
-                     &value);
       //g_print ("got %s -> %s\n", key, g_variant_markup_print (value, FALSE, 0, 0));
 
       g_hash_table_insert (proxy->priv->properties,
-                           key,
-                           value); /* steals value */
+                           key, /* adopts string */
+                           value); /* adopts value */
     }
+  g_variant_iter_free (iter);
+
  out:
   ;
 }



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