[clutter] Do not leak strings from GKeyFile



commit 7bd5659962c34b54631074212f4746394a076564
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Oct 11 22:43:54 2011 +0100

    Do not leak strings from GKeyFile
    
    The string getters always copy, so we need to free the returned
    values.

 clutter/clutter-main.c     |   12 ++++++++++--
 clutter/clutter-settings.c |    4 ++--
 2 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c
index 28b2857..2cd5649 100644
--- a/clutter/clutter-main.c
+++ b/clutter/clutter-main.c
@@ -225,7 +225,7 @@ clutter_config_read_from_key_file (GKeyFile *keyfile)
   GError *key_error = NULL;
   gboolean bool_value;
   gint int_value;
-  const gchar *str_value;
+  gchar *str_value;
 
   if (!g_key_file_has_group (keyfile, ENVIRONMENT_GROUP))
     return;
@@ -294,6 +294,8 @@ clutter_config_read_from_key_file (GKeyFile *keyfile)
       else
         clutter_text_direction = CLUTTER_TEXT_DIRECTION_LTR;
     }
+
+  g_free (str_value);
 }
 
 #ifdef CLUTTER_ENABLE_DEBUG
@@ -301,7 +303,7 @@ static void
 clutter_debug_read_from_key_file (GKeyFile *keyfile)
 {
   GError *key_error = NULL;
-  const gchar *value;
+  gchar *value;
 
   if (!g_key_file_has_group (keyfile, DEBUG_GROUP))
     return;
@@ -319,6 +321,8 @@ clutter_debug_read_from_key_file (GKeyFile *keyfile)
   else
     g_clear_error (&key_error);
 
+  g_free (value);
+
   value = g_key_file_get_value (keyfile, DEBUG_GROUP,
                                 "PaintDebug",
                                 &key_error);
@@ -332,6 +336,8 @@ clutter_debug_read_from_key_file (GKeyFile *keyfile)
   else
     g_clear_error (&key_error);
 
+  g_free (value);
+
   value = g_key_file_get_value (keyfile, DEBUG_GROUP,
                                 "PickDebug",
                                 &key_error);
@@ -344,6 +350,8 @@ clutter_debug_read_from_key_file (GKeyFile *keyfile)
     }
   else
     g_clear_error (&key_error);
+
+  g_free (value);
 }
 #endif
 
diff --git a/clutter/clutter-settings.c b/clutter/clutter-settings.c
index 293f646..d61620f 100644
--- a/clutter/clutter-settings.c
+++ b/clutter/clutter-settings.c
@@ -760,12 +760,12 @@ _clutter_settings_read_from_key_file (ClutterSettings *settings,
 
         case G_TYPE_STRING:
           {
-            const gchar *val;
+            gchar *val;
 
             val = g_key_file_get_string (keyfile,
                                          SETTINGS_GROUP, p_name,
                                          &key_error);
-            g_value_set_string (&value, val);
+            g_value_take_string (&value, val);
           }
           break;
         }



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