Kaydet (Commit) c0cde4da authored tarafından Neal Norwitz's avatar Neal Norwitz

Fix memory leak under some conditions.

Reported by Klocwork, #98.
üst 5eaf7729
...@@ -1906,11 +1906,10 @@ PyImport_ImportFrozenModule(char *name) ...@@ -1906,11 +1906,10 @@ PyImport_ImportFrozenModule(char *name)
if (co == NULL) if (co == NULL)
return -1; return -1;
if (!PyCode_Check(co)) { if (!PyCode_Check(co)) {
Py_DECREF(co);
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"frozen object %.200s is not a code object", "frozen object %.200s is not a code object",
name); name);
return -1; goto err_return;
} }
if (ispackage) { if (ispackage) {
/* Set __path__ to the package name */ /* Set __path__ to the package name */
...@@ -1918,22 +1917,25 @@ PyImport_ImportFrozenModule(char *name) ...@@ -1918,22 +1917,25 @@ PyImport_ImportFrozenModule(char *name)
int err; int err;
m = PyImport_AddModule(name); m = PyImport_AddModule(name);
if (m == NULL) if (m == NULL)
return -1; goto err_return;
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
s = PyString_InternFromString(name); s = PyString_InternFromString(name);
if (s == NULL) if (s == NULL)
return -1; goto err_return;
err = PyDict_SetItemString(d, "__path__", s); err = PyDict_SetItemString(d, "__path__", s);
Py_DECREF(s); Py_DECREF(s);
if (err != 0) if (err != 0)
return err; goto err_return;
} }
m = PyImport_ExecCodeModuleEx(name, co, "<frozen>"); m = PyImport_ExecCodeModuleEx(name, co, "<frozen>");
Py_DECREF(co);
if (m == NULL) if (m == NULL)
return -1; goto err_return;
Py_DECREF(co);
Py_DECREF(m); Py_DECREF(m);
return 1; return 1;
err_return:
Py_DECREF(co);
return -1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment