[gimp/multi-stroke: 30/31] app: memory leak fixes.



commit 7511c28a24aab79cb8f0b92026b33cf3ef9bf6b0
Author: Jehan <jehan girinstud io>
Date:   Thu Jun 4 18:53:07 2015 +0200

    app: memory leak fixes.
    
    Thanks Massimo:
    "The GList*  returned by 'gimp_image_symmetry_list' is not freed in few places
    and the char* returned by 'gimp_symmetry_parasite_name' is passed directly to
    functions that do not free it and so it is leaked."

 app/core/gimpsymmetry.c          |   11 +++++++++--
 app/tools/gimppaintoptions-gui.c |    9 ++++++---
 app/xcf/xcf-load.c               |    6 ++++--
 3 files changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/app/core/gimpsymmetry.c b/app/core/gimpsymmetry.c
index b5303b3..2d83918 100644
--- a/app/core/gimpsymmetry.c
+++ b/app/core/gimpsymmetry.c
@@ -396,6 +396,7 @@ GimpParasite *
 gimp_symmetry_to_parasite (const GimpSymmetry *sym)
 {
   GimpParasite *parasite;
+  gchar        *parasite_name;
   gchar        *str;
 
   g_return_val_if_fail (GIMP_IS_SYMMETRY (sym), NULL);
@@ -403,9 +404,11 @@ gimp_symmetry_to_parasite (const GimpSymmetry *sym)
   str = gimp_config_serialize_to_string (GIMP_CONFIG (sym), NULL);
   g_return_val_if_fail (str != NULL, NULL);
 
-  parasite = gimp_parasite_new (gimp_symmetry_parasite_name (sym->type),
+  parasite_name = gimp_symmetry_parasite_name (sym->type);
+  parasite = gimp_parasite_new (parasite_name,
                                 GIMP_PARASITE_PERSISTENT,
                                 strlen (str) + 1, str);
+  g_free (parasite_name);
   g_free (str);
 
   return parasite;
@@ -417,13 +420,17 @@ gimp_symmetry_from_parasite (const GimpParasite *parasite,
                              GType               type)
 {
   GimpSymmetry    *symmetry;
+  gchar           *parasite_name;
   const gchar     *str;
   GError          *error = NULL;
 
+  parasite_name = gimp_symmetry_parasite_name (type);
+
   g_return_val_if_fail (parasite != NULL, NULL);
   g_return_val_if_fail (strcmp (gimp_parasite_name (parasite),
-                                gimp_symmetry_parasite_name (type)) == 0,
+                                parasite_name) == 0,
                         NULL);
+  g_free (parasite_name);
 
   str = gimp_parasite_data (parasite);
   g_return_val_if_fail (str != NULL, NULL);
diff --git a/app/tools/gimppaintoptions-gui.c b/app/tools/gimppaintoptions-gui.c
index 71b515f..d503081 100644
--- a/app/tools/gimppaintoptions-gui.c
+++ b/app/tools/gimppaintoptions-gui.c
@@ -262,16 +262,17 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
           GtkListStore *store;
           GtkTreeIter   iter;
           GList        *syms;
+          GList        *sym_iter;
 
           store = gimp_int_store_new ();
 
           syms = gimp_image_symmetry_list ();
-          for (syms = gimp_image_symmetry_list (); syms; syms = g_list_next (syms))
+          for (sym_iter = syms; sym_iter; sym_iter = g_list_next (sym_iter))
             {
               GimpSymmetryClass *klass;
               GType              type;
 
-              type = (GType) syms->data;
+              type = (GType) sym_iter->data;
               klass = g_type_class_ref (type);
 
               gtk_list_store_prepend (store, &iter);
@@ -279,10 +280,12 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
                                   GIMP_INT_STORE_LABEL,
                                   klass->label,
                                   GIMP_INT_STORE_VALUE,
-                                  syms->data,
+                                  sym_iter->data,
                                   -1);
               g_type_class_unref (klass);
             }
+          g_list_free (syms);
+
           gtk_list_store_prepend (store, &iter);
           gtk_list_store_set (store, &iter,
                               GIMP_INT_STORE_LABEL, _("None"),
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index 09e55b2..e433edf 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -159,6 +159,7 @@ xcf_load_image (Gimp     *gimp,
   gint                image_type;
   GimpPrecision       precision = GIMP_PRECISION_U8_GAMMA;
   gint                num_successful_elements = 0;
+  GList              *syms;
   GList              *iter;
 
   /* read in the image width, height and type */
@@ -273,7 +274,8 @@ xcf_load_image (Gimp     *gimp,
     }
 
   /* check for symmetry parasites */
-  for (iter = gimp_image_symmetry_list (); iter; iter = g_list_next (iter))
+  syms = gimp_image_symmetry_list ();
+  for (iter = syms; iter; iter = g_list_next (iter))
     {
       GType  type = (GType) iter->data;
       gchar *parasite_name = gimp_symmetry_parasite_name (type);
@@ -302,7 +304,7 @@ xcf_load_image (Gimp     *gimp,
             }
         }
     }
-
+  g_list_free (syms);
 
   /* migrate the old "exif-data" parasite */
   parasite = gimp_image_parasite_find (GIMP_IMAGE (image),


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