Commit 26fabe13 authored by Victor Stinner's avatar Victor Stinner

zipimporter_load_module() doesn't destroy mod on error

PyImport_AddModule() returns a borrowed reference. Don't display "import ... #
loaded from Zip ..." on error.
parent 72f767e6
...@@ -309,7 +309,7 @@ static PyObject * ...@@ -309,7 +309,7 @@ static PyObject *
zipimporter_load_module(PyObject *obj, PyObject *args) zipimporter_load_module(PyObject *obj, PyObject *args)
{ {
ZipImporter *self = (ZipImporter *)obj; ZipImporter *self = (ZipImporter *)obj;
PyObject *code, *mod, *dict; PyObject *code = NULL, *mod, *dict;
char *fullname, *modpath; char *fullname, *modpath;
int ispackage; int ispackage;
...@@ -319,13 +319,11 @@ zipimporter_load_module(PyObject *obj, PyObject *args) ...@@ -319,13 +319,11 @@ zipimporter_load_module(PyObject *obj, PyObject *args)
code = get_module_code(self, fullname, &ispackage, &modpath); code = get_module_code(self, fullname, &ispackage, &modpath);
if (code == NULL) if (code == NULL)
return NULL; goto error;
mod = PyImport_AddModule(fullname); mod = PyImport_AddModule(fullname);
if (mod == NULL) { if (mod == NULL)
Py_DECREF(code); goto error;
return NULL;
}
dict = PyModule_GetDict(mod); dict = PyModule_GetDict(mod);
/* mod.__loader__ = self */ /* mod.__loader__ = self */
...@@ -355,14 +353,16 @@ zipimporter_load_module(PyObject *obj, PyObject *args) ...@@ -355,14 +353,16 @@ zipimporter_load_module(PyObject *obj, PyObject *args)
goto error; goto error;
} }
mod = PyImport_ExecCodeModuleEx(fullname, code, modpath); mod = PyImport_ExecCodeModuleEx(fullname, code, modpath);
Py_DECREF(code); Py_CLEAR(code);
if (mod == NULL)
goto error;
if (Py_VerboseFlag) if (Py_VerboseFlag)
PySys_WriteStderr("import %s # loaded from Zip %s\n", PySys_WriteStderr("import %s # loaded from Zip %s\n",
fullname, modpath); fullname, modpath);
return mod; return mod;
error: error:
Py_DECREF(code); Py_XDECREF(code);
Py_DECREF(mod);
return NULL; return NULL;
} }
......
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