[pygobject/pygobject-3-10] Fix memory leak for caller allocated GValue out arguments



commit 073f3870f2671a387d99529bab386f2218f44e2e
Author: Simon Feltman <sfeltman src gnome org>
Date:   Thu Oct 3 19:25:34 2013 -0700

    Fix memory leak for caller allocated GValue out arguments
    
    Swizzle the order of type checks in _cleanup_caller_allocates so
    G_TYPE_VALUE arguments are checked before G_TYPE_BOXED. The ordering is
    important because G_TYPE_VALUE is a sub-type of boxed and so its specialized
    cleanup code was never being called (g_value_unset).
    Additionally update check to use g_type_is_a instead of a compare to handle
    the potential case of a G_TYPE_VALUE sub-type.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=709397

 gi/pygi-marshal-cleanup.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/gi/pygi-marshal-cleanup.c b/gi/pygi-marshal-cleanup.c
index d7d1b63..c197bab 100644
--- a/gi/pygi-marshal-cleanup.c
+++ b/gi/pygi-marshal-cleanup.c
@@ -29,16 +29,17 @@ _cleanup_caller_allocates (PyGIInvokeState    *state,
 {
     PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)cache;
 
-    if (g_type_is_a (iface_cache->g_type, G_TYPE_BOXED)) {
+    /* check GValue first because GValue is also a boxed sub-type */
+    if (g_type_is_a (iface_cache->g_type, G_TYPE_VALUE)) {
+        if (was_processed)
+            g_value_unset (data);
+        g_slice_free (GValue, data);
+    } else if (g_type_is_a (iface_cache->g_type, G_TYPE_BOXED)) {
         gsize size;
         if (was_processed)
             return; /* will be cleaned up at deallocation */
         size = g_struct_info_get_size (iface_cache->interface_info);
         g_slice_free1 (size, data);
-    } else if (iface_cache->g_type == G_TYPE_VALUE) {
-        if (was_processed)
-            g_value_unset (data);
-        g_slice_free (GValue, data);
     } else if (iface_cache->is_foreign) {
         if (was_processed)
             return; /* will be cleaned up at deallocation */


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