[Python-checkins] cpython: Fix refleak introduced by #10812.

ross.lagerwall python-checkins at python.org
Sat Mar 19 08:19:58 CET 2011


http://hg.python.org/cpython/rev/96e09d039433
changeset:   68674:96e09d039433
user:        Ross Lagerwall <rosslagerwall at gmail.com>
date:        Sat Mar 19 09:11:14 2011 +0200
summary:
  Fix refleak introduced by #10812.

files:
  Modules/posixmodule.c

diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -3827,16 +3827,19 @@
         return NULL;
     }
     for (i = 0; i < *argc; i++) {
-        if (!fsconvert_strdup(PySequence_ITEM(argv, i),
-                              &argvlist[i]))
-        {
-            *argc = i;
+        PyObject* item = PySequence_ITEM(argv, i);
+        if (item == NULL)
+            goto fail;
+        if (!fsconvert_strdup(item, &argvlist[i])) {
+            Py_DECREF(item);
             goto fail;
         }
+        Py_DECREF(item);
     }
     argvlist[*argc] = NULL;
     return argvlist;
 fail:
+    *argc = i;
     free_string_array(argvlist, *argc);
     return NULL;
 }
@@ -6177,22 +6180,28 @@
     }
 
     for (i = 0; i < cnt; i++) {
-        if (PyObject_GetBuffer(PySequence_GetItem(seq, i),
-                               &(*buf)[i], type) == -1) {
-            PyMem_Del(*iov);
-            for (j = 0; j < i; j++) {
-                PyBuffer_Release(&(*buf)[j]);
-            }
-            PyMem_Del(*buf);
-            total = 0;
-            return total;
+        PyObject *item = PySequence_GetItem(seq, i);
+        if (item == NULL)
+            goto fail;
+        if (PyObject_GetBuffer(item, &(*buf)[i], type) == -1) {
+            Py_DECREF(item);
+            goto fail;
         }
+        Py_DECREF(item);
         (*iov)[i].iov_base = (*buf)[i].buf;
         blen = (*buf)[i].len;
         (*iov)[i].iov_len = blen;
         total += blen;
     }
     return total;
+
+fail:
+    PyMem_Del(*iov);
+    for (j = 0; j < i; j++) {
+        PyBuffer_Release(&(*buf)[j]);
+    }
+    PyMem_Del(*buf);
+    return 0;
 }
 
 static void

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list