summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-05-19 22:16:09 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-05-19 22:16:09 (GMT)
commit4925cde1cc20fe559b9c1429a99bf9b1c17f7048 (patch)
treec12bdc58924c3771db0720d7ec5dff91d2664cfc /Modules
parentae8856fe363c65c66f3ae61b57ea2af886c61e32 (diff)
downloadcpython-4925cde1cc20fe559b9c1429a99bf9b1c17f7048.zip
cpython-4925cde1cc20fe559b9c1429a99bf9b1c17f7048.tar.gz
cpython-4925cde1cc20fe559b9c1429a99bf9b1c17f7048.tar.bz2
Issue #12124: zipimport doesn't keep a reference to zlib.decompress() anymore
to be able to unload the module.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/zipimport.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index fb5f42b..e874498 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -785,35 +785,33 @@ error:
/* Return the zlib.decompress function object, or NULL if zlib couldn't
be imported. The function is cached when found, so subsequent calls
- don't import zlib again. Returns a *borrowed* reference.
- XXX This makes zlib.decompress immortal. */
+ don't import zlib again. */
static PyObject *
get_decompress_func(void)
{
- static PyObject *decompress = NULL;
+ static int importing_zlib = 0;
+ PyObject *zlib;
+ PyObject *decompress;
- if (decompress == NULL) {
- PyObject *zlib;
- static int importing_zlib = 0;
-
- if (importing_zlib != 0)
- /* Someone has a zlib.py[co] in their Zip file;
- let's avoid a stack overflow. */
- return NULL;
- importing_zlib = 1;
- zlib = PyImport_ImportModuleNoBlock("zlib");
- importing_zlib = 0;
- if (zlib != NULL) {
- decompress = PyObject_GetAttrString(zlib,
- "decompress");
- Py_DECREF(zlib);
- }
- else
- PyErr_Clear();
- if (Py_VerboseFlag)
- PySys_WriteStderr("# zipimport: zlib %s\n",
- zlib != NULL ? "available": "UNAVAILABLE");
+ if (importing_zlib != 0)
+ /* Someone has a zlib.py[co] in their Zip file;
+ let's avoid a stack overflow. */
+ return NULL;
+ importing_zlib = 1;
+ zlib = PyImport_ImportModuleNoBlock("zlib");
+ importing_zlib = 0;
+ if (zlib != NULL) {
+ decompress = PyObject_GetAttrString(zlib,
+ "decompress");
+ Py_DECREF(zlib);
+ }
+ else {
+ PyErr_Clear();
+ decompress = NULL;
}
+ if (Py_VerboseFlag)
+ PySys_WriteStderr("# zipimport: zlib %s\n",
+ zlib != NULL ? "available": "UNAVAILABLE");
return decompress;
}
@@ -904,6 +902,7 @@ get_data(char *archive, PyObject *toc_entry)
goto error;
}
data = PyObject_CallFunction(decompress, "Oi", raw_data, -15);
+ Py_DECREF(decompress);
error:
Py_DECREF(raw_data);
return data;