[glib] gsettings tool: fix a memory error



commit 387ed239e236cad1c3a54d08a34194c36bb59dba
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Feb 2 10:48:11 2012 -0500

    gsettings tool: fix a memory error
    
    8852d4e9a08e7fbc9df7fb99a54b112f5049ee19 introduced a memory error by
    taking the type of a GVariant, freeing the GVariant and using the type
    after the free.
    
    This delays the free until after we've used the type.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=669253

 gio/gsettings-tool.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
---
diff --git a/gio/gsettings-tool.c b/gio/gsettings-tool.c
index 993fa59..a232602 100644
--- a/gio/gsettings-tool.c
+++ b/gio/gsettings-tool.c
@@ -457,7 +457,6 @@ gsettings_set (GSettings   *settings,
 
   existing = g_settings_get_value (settings, key);
   type = g_variant_get_type (existing);
-  g_variant_unref (existing);
 
   new = g_variant_parse (type, value, NULL, NULL, &error);
 
@@ -490,6 +489,9 @@ gsettings_set (GSettings   *settings,
       new = g_variant_new_string (value);
     }
 
+  /* we're done with 'type' now, so we can free 'existing' */
+  g_variant_unref (existing);
+
   if (new == NULL)
     {
       g_printerr ("%s\n", error->message);



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