]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[Backport r50678 | neal.norwitz]
authorAndrew M. Kuchling <amk@amk.ca>
Tue, 3 Oct 2006 18:32:25 +0000 (18:32 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Tue, 3 Oct 2006 18:32:25 +0000 (18:32 +0000)
Fix memory leak under some conditions.

Reported by Klocwork, #98.

Python/import.c

index 5033819d8c454f3248f957683958ce37b823a87d..fff4b836b8bfda3a05b19d87e0d8677d6bb0b9b6 100644 (file)
@@ -1847,11 +1847,10 @@ PyImport_ImportFrozenModule(char *name)
        if (co == NULL)
                return -1;
        if (!PyCode_Check(co)) {
-               Py_DECREF(co);
                PyErr_Format(PyExc_TypeError,
                             "frozen object %.200s is not a code object",
                             name);
-               return -1;
+               goto err_return;
        }
        if (ispackage) {
                /* Set __path__ to the package name */
@@ -1859,22 +1858,25 @@ PyImport_ImportFrozenModule(char *name)
                int err;
                m = PyImport_AddModule(name);
                if (m == NULL)
-                       return -1;
+                       goto err_return;
                d = PyModule_GetDict(m);
                s = PyString_InternFromString(name);
                if (s == NULL)
-                       return -1;
+                       goto err_return;
                err = PyDict_SetItemString(d, "__path__", s);
                Py_DECREF(s);
                if (err != 0)
-                       return err;
+                       goto err_return;
        }
        m = PyImport_ExecCodeModuleEx(name, co, "<frozen>");
-       Py_DECREF(co);
        if (m == NULL)
-               return -1;
+               goto err_return;
+       Py_DECREF(co);
        Py_DECREF(m);
        return 1;
+err_return:
+       Py_DECREF(co);
+       return -1;
 }