[gimp/gimp-2-10] Issue #1974: Memory leak in gimpimage.c.



commit 8909684b59a5e935ba7e2af83fdf38cf7ed72ac8
Author: Jehan <jehan girinstud io>
Date:   Sat Aug 4 09:34:05 2018 +0200

    Issue #1974: Memory leak in gimpimage.c.
    
    ADD_REASON macro was leaking the allocated string when version_reason
    return value was NULL (i.e. when we didn't care about the version
    reasons).
    
    Also we were not properly freeing all the reason strings at the end,
    only the list. Use g_list_free_full() instead of g_list_free().
    
    (cherry picked from commit 0ab682b0f5bd2ddf8e6a8f8915967a60fb99a4f9)

 app/core/gimpimage.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index ad209ec9a7..101fe20bb3 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -2357,7 +2357,8 @@ gimp_image_get_xcf_version (GimpImage    *image,
     if (g_list_find_custom (reasons, tmp, (GCompareFunc) strcmp)) \
       g_free (tmp);                                               \
     else                                                          \
-      reasons = g_list_prepend (reasons, (_reason)); }
+      reasons = g_list_prepend (reasons, (_reason)); }            \
+  else g_free (_reason);
 
   /* need version 1 for colormaps */
   if (gimp_image_get_colormap (image))
@@ -2570,10 +2571,10 @@ gimp_image_get_xcf_version (GimpImage    *image,
             g_string_append_c (reason, '\n');
         }
 
-      g_list_free (reasons);
-
       *version_reason = g_string_free (reason, FALSE);
     }
+  if (reasons)
+    g_list_free_full (reasons, g_free);
 
   return version;
 }


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