[pygobject: 2/2] Unref interface info when fetching enums or flags



commit ce0ad7066ebdb7018fdce58dc32bbaa715206a0c
Author: Mike Gorse <mgorse suse com>
Date:   Wed Jul 10 12:10:16 2013 -0500

    Unref interface info when fetching enums or flags
    
    When calling g_type_info_get_interface, the resulting interface should
    be dereferenced by calling g_base_info_unref.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=703960

 gi/pygi-marshal-from-py.c |    8 +++++++-
 gi/pygi-marshal-to-py.c   |    3 +++
 2 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 4ff9fce..8065d19 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -1536,7 +1536,7 @@ _pygi_marshal_from_py_interface_enum (PyGIInvokeState   *state,
     long c_long;
     gint is_instance;
     PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
-    GIBaseInfo *interface;
+    GIBaseInfo *interface = NULL;
 
     is_instance = PyObject_IsInstance (py_arg, iface_cache->py_type);
 
@@ -1556,6 +1556,7 @@ _pygi_marshal_from_py_interface_enum (PyGIInvokeState   *state,
                                  c_long,
                                  g_enum_info_get_storage_type ((GIEnumInfo *)interface))) {
           g_assert_not_reached();
+          g_base_info_unref (interface);
           return FALSE;
     }
 
@@ -1581,9 +1582,12 @@ _pygi_marshal_from_py_interface_enum (PyGIInvokeState   *state,
             goto err;
     }
 
+    g_base_info_unref (interface);
     return TRUE;
 
 err:
+    if (interface)
+        g_base_info_unref (interface);
     PyErr_Format (PyExc_TypeError, "Expected a %s, but got %s",
                   iface_cache->type_name, py_arg->ob_type->tp_name);
     return FALSE;
@@ -1622,9 +1626,11 @@ _pygi_marshal_from_py_interface_flags (PyGIInvokeState   *state,
     g_assert (g_base_info_get_type (interface) == GI_INFO_TYPE_FLAGS);
     if (!gi_argument_from_c_long(arg, c_long,
                                  g_enum_info_get_storage_type ((GIEnumInfo *)interface))) {
+        g_base_info_unref (interface);
         return FALSE;
     }
 
+    g_base_info_unref (interface);
     return TRUE;
 
 err:
diff --git a/gi/pygi-marshal-to-py.c b/gi/pygi-marshal-to-py.c
index 6e16b99..c34015b 100644
--- a/gi/pygi-marshal-to-py.c
+++ b/gi/pygi-marshal-to-py.c
@@ -740,6 +740,7 @@ _pygi_marshal_to_py_interface_enum (PyGIInvokeState   *state,
     } else {
         py_obj = pyg_enum_from_gtype (iface_cache->g_type, c_long);
     }
+    g_base_info_unref (interface);
     return py_obj;
 }
 
@@ -759,9 +760,11 @@ _pygi_marshal_to_py_interface_flags (PyGIInvokeState   *state,
 
     if (!gi_argument_to_c_long(arg, &c_long,
                                g_enum_info_get_storage_type ((GIEnumInfo *)interface))) {
+        g_base_info_unref (interface);
         return NULL;
     }
 
+    g_base_info_unref (interface);
     if (iface_cache->g_type == G_TYPE_NONE) {
         /* An enum with a GType of None is an enum without GType */
 


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