[Python-checkins] cpython: Issue 13085: Fix some memory leaks. Patch by Stefan Krah.

martin.v.loewis python-checkins at python.org
Sat Oct 1 16:35:48 CEST 2011


http://hg.python.org/cpython/rev/1b203e741fb2
changeset:   72563:1b203e741fb2
user:        Martin v. Löwis <martin at v.loewis.de>
date:        Sat Oct 01 16:35:40 2011 +0200
summary:
  Issue 13085: Fix some memory leaks. Patch by Stefan Krah.

files:
  Objects/unicodeobject.c |   1 +
  Python/import.c         |  30 ++++++++++++++++++----------
  2 files changed, 20 insertions(+), 11 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9075,6 +9075,7 @@
                    PyUnicode_KIND_SIZE(rkind, slen-i));
         }
         u = PyUnicode_FromKindAndData(rkind, res, new_size);
+        PyMem_Free(res);
     }
     if (srelease)
         PyMem_FREE(sbuf);
diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -1564,8 +1564,10 @@
     if (py == NULL)
         goto error;
 
-    if (_Py_stat(py, &statbuf) == 0 && S_ISREG(statbuf.st_mode))
+    if (_Py_stat(py, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) {
+        PyMem_Free(fileuni);
         return py;
+    }
     Py_DECREF(py);
     goto unchanged;
 
@@ -3074,7 +3076,7 @@
     Py_ssize_t len;
     Py_UCS4 *p;
     PyObject *fullname, *name, *result, *mark_name;
-    const Py_UCS4 *nameuni;
+    Py_UCS4 *nameuni;
 
     *p_outputname = NULL;
 
@@ -3095,7 +3097,7 @@
         if (len == 0) {
             PyErr_SetString(PyExc_ValueError,
                             "Empty module name");
-            return NULL;
+            goto error;
         }
     }
     else
@@ -3104,7 +3106,7 @@
     if (*p_buflen+len+1 >= bufsize) {
         PyErr_SetString(PyExc_ValueError,
                         "Module name too long");
-        return NULL;
+        goto error;
     }
 
     p = buf + *p_buflen;
@@ -3119,12 +3121,12 @@
     fullname = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND,
                                          buf, *p_buflen);
     if (fullname == NULL)
-        return NULL;
+        goto error;
     name = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND,
                                      p, len);
     if (name == NULL) {
         Py_DECREF(fullname);
-        return NULL;
+        goto error;
     }
     result = import_submodule(mod, name, fullname);
     Py_DECREF(fullname);
@@ -3138,12 +3140,12 @@
                                                   buf, *p_buflen);
             if (mark_name == NULL) {
                 Py_DECREF(result);
-                return NULL;
+                goto error;
             }
             if (mark_miss(mark_name) != 0) {
                 Py_DECREF(result);
                 Py_DECREF(mark_name);
-                return NULL;
+                goto error;
             }
             Py_DECREF(mark_name);
             Py_UCS4_strncpy(buf, nameuni, len);
@@ -3154,13 +3156,13 @@
     else
         Py_DECREF(name);
     if (result == NULL)
-        return NULL;
+        goto error;
 
     if (result == Py_None) {
         Py_DECREF(result);
         PyErr_Format(PyExc_ImportError,
                      "No module named %R", inputname);
-        return NULL;
+        goto error;
     }
 
     if (dot != NULL) {
@@ -3168,11 +3170,17 @@
                                                   dot+1, Py_UCS4_strlen(dot+1));
         if (*p_outputname == NULL) {
             Py_DECREF(result);
-            return NULL;
+            goto error;
         }
     }
 
+out:
+    PyMem_Free(nameuni);
     return result;
+
+error:
+    PyMem_Free(nameuni);
+    return NULL;
 }
 
 static int

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


More information about the Python-checkins mailing list