[pygobject] Fix memory leak for caller allocated GValue out arguments



commit d644cbd0c0ad85142286754838db848c4eb1707f
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 57ded65..a877306 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]