[gimp] Issue #1974: Memory leak in gimpimage.c.



commit 0ab682b0f5bd2ddf8e6a8f8915967a60fb99a4f9
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().

 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 9040bd0fdd..b38f281774 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -2373,7 +2373,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))
@@ -2590,10 +2591,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]