summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-18 12:03:25 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-18 12:03:25 (GMT)
commit26fabe13698addebe83e1a57daa8f180c9ad8e1d (patch)
treef8b328686b188a48fdc6f9d20c5eb37b9e623f98
parent72f767e601651f3cedb169491ab3b141eb559d53 (diff)
downloadcpython-26fabe13698addebe83e1a57daa8f180c9ad8e1d.zip
cpython-26fabe13698addebe83e1a57daa8f180c9ad8e1d.tar.gz
cpython-26fabe13698addebe83e1a57daa8f180c9ad8e1d.tar.bz2
zipimporter_load_module() doesn't destroy mod on error
PyImport_AddModule() returns a borrowed reference. Don't display "import ... # loaded from Zip ..." on error.
-rw-r--r--Modules/zipimport.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 64dbdbc..a35b8c8 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -309,7 +309,7 @@ static PyObject *
zipimporter_load_module(PyObject *obj, PyObject *args)
{
ZipImporter *self = (ZipImporter *)obj;
- PyObject *code, *mod, *dict;
+ PyObject *code = NULL, *mod, *dict;
char *fullname, *modpath;
int ispackage;
@@ -319,13 +319,11 @@ zipimporter_load_module(PyObject *obj, PyObject *args)
code = get_module_code(self, fullname, &ispackage, &modpath);
if (code == NULL)
- return NULL;
+ goto error;
mod = PyImport_AddModule(fullname);
- if (mod == NULL) {
- Py_DECREF(code);
- return NULL;
- }
+ if (mod == NULL)
+ goto error;
dict = PyModule_GetDict(mod);
/* mod.__loader__ = self */
@@ -355,14 +353,16 @@ zipimporter_load_module(PyObject *obj, PyObject *args)
goto error;
}
mod = PyImport_ExecCodeModuleEx(fullname, code, modpath);
- Py_DECREF(code);
+ Py_CLEAR(code);
+ if (mod == NULL)
+ goto error;
+
if (Py_VerboseFlag)
PySys_WriteStderr("import %s # loaded from Zip %s\n",
fullname, modpath);
return mod;
error:
- Py_DECREF(code);
- Py_DECREF(mod);
+ Py_XDECREF(code);
return NULL;
}