summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-10-09 15:06:19 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-10-09 15:06:19 (GMT)
commitc0cabc23bbe474d542ff8a4f1243f4ec3cce5549 (patch)
tree93821190071fa7e71852c28e5079f138654def13 /Modules
parent4d3f084c035ad3dfd9f8479886c41b1b1823ace2 (diff)
downloadcpython-c0cabc23bbe474d542ff8a4f1243f4ec3cce5549.zip
cpython-c0cabc23bbe474d542ff8a4f1243f4ec3cce5549.tar.gz
cpython-c0cabc23bbe474d542ff8a4f1243f4ec3cce5549.tar.bz2
bpo-31723: Fix refleaks when zipimporter.__init__() is called more than once (GH-3919)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/zipimport.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 493e6db..895cd80 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -164,10 +164,10 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)
}
else
Py_INCREF(files);
- self->files = files;
+ Py_XSETREF(self->files, files);
/* Transfer reference */
- self->archive = filename;
+ Py_XSETREF(self->archive, filename);
filename = NULL;
/* Check if there is a prefix directory following the filename. */
@@ -176,7 +176,7 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)
PyUnicode_GET_LENGTH(path));
if (tmp == NULL)
goto error;
- self->prefix = tmp;
+ Py_XSETREF(self->prefix, tmp);
if (PyUnicode_READ_CHAR(path, len-1) != SEP) {
/* add trailing SEP */
tmp = PyUnicode_FromFormat("%U%c", self->prefix, SEP);
@@ -185,8 +185,9 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)
Py_SETREF(self->prefix, tmp);
}
}
- else
- self->prefix = PyUnicode_New(0, 0);
+ else {
+ Py_XSETREF(self->prefix, PyUnicode_New(0, 0));
+ }
Py_DECREF(path);
return 0;