[pygobject] Avoid duping filenames when marshalling from Python to C



commit 2dcce92b4fab95403b9bbedffa8a91453c947927
Author: Garrett Regier <garrettregier gmail com>
Date:   Fri Jan 23 01:37:35 2015 -0800

    Avoid duping filenames when marshalling from Python to C
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744719

 gi/pygi-basictype.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/gi/pygi-basictype.c b/gi/pygi-basictype.c
index e199741..432559d 100644
--- a/gi/pygi-basictype.c
+++ b/gi/pygi-basictype.c
@@ -253,18 +253,18 @@ _pygi_marshal_from_py_filename (PyObject          *py_arg,
 {
     gchar *string_;
     GError *error = NULL;
+    PyObject *tmp = NULL;
 
     if (PyUnicode_Check (py_arg)) {
-        PyObject *pystr_obj = PyUnicode_AsUTF8String (py_arg);
-        if (!pystr_obj)
+        tmp = PyUnicode_AsUTF8String (py_arg);
+        if (!tmp)
             return FALSE;
 
-        string_ = g_strdup (PYGLIB_PyBytes_AsString (pystr_obj));
-        Py_DECREF (pystr_obj);
+        string_ = PYGLIB_PyBytes_AsString (tmp);
     }
 #if PY_VERSION_HEX < 0x03000000
     else if (PyString_Check (py_arg)) {
-        string_ = g_strdup (PyString_AsString (py_arg));
+        string_ = PyString_AsString (py_arg);
     }
 #endif
     else {
@@ -274,7 +274,7 @@ _pygi_marshal_from_py_filename (PyObject          *py_arg,
     }
 
     arg->v_string = g_filename_from_utf8 (string_, -1, NULL, NULL, &error);
-    g_free (string_);
+    Py_XDECREF (tmp);
 
     if (arg->v_string == NULL) {
         PyErr_SetString (PyExc_Exception, error->message);


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