[nautilus-python] python-object: Fix a memory leak



commit 8908c4749829d6306339fb8d54dd872d08203662
Author: Michael Webster <miketwebster gmail com>
Date:   Fri Jul 5 18:08:58 2019 -0400

    python-object: Fix a memory leak
    
    PyObject_GetAttrString() returns new reference:
    
    https://docs.python.org/3/c-api/object.html#c.PyObject_GetAttrString

 src/nautilus-python-object.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/src/nautilus-python-object.c b/src/nautilus-python-object.c
index da84bc3..167135e 100644
--- a/src/nautilus-python-object.c
+++ b/src/nautilus-python-object.c
@@ -448,6 +448,7 @@ nautilus_python_object_class_init (NautilusPythonObjectClass *class,
 GType 
 nautilus_python_object_get_type (GTypeModule *module, 
                                  PyObject     *type) {
+    PyObject *name_str = NULL;
     g_autofree GTypeInfo *info = NULL;
     g_autofree gchar *type_name = NULL;
     GType gtype;
@@ -482,7 +483,8 @@ nautilus_python_object_get_type (GTypeModule *module,
         NULL
     };
 
-    debug_enter_args("type=%s", PyUnicode_AsUTF8(PyObject_GetAttrString(type, "__name__")));
+    name_str = PyObject_GetAttrString(type, "__name__");
+    debug_enter_args("type=%s", PyUnicode_AsUTF8(name_str));
     info = g_new0 (GTypeInfo, 1);
     
     info->class_size = sizeof (NautilusPythonObjectClass);
@@ -493,9 +495,10 @@ nautilus_python_object_get_type (GTypeModule *module,
     info->class_data = type;
     Py_INCREF(type);
 
-    type_name = g_strdup_printf("%s+NautilusPython",
-                                PyUnicode_AsUTF8(PyObject_GetAttrString(type, "__name__")));
-        
+    type_name = g_strdup_printf("%s+NautilusPython", PyUnicode_AsUTF8(name_str));
+
+    Py_XDECREF(name_str);
+
     gtype = g_type_module_register_type (module, 
                                          G_TYPE_OBJECT,
                                          type_name,


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