Commit c0cabc23 authored by Oren Milman's avatar Oren Milman Committed by Victor Stinner

bpo-31723: Fix refleaks when zipimporter.__init__() is called more than once (GH-3919)

parent 4d3f084c
...@@ -164,10 +164,10 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path) ...@@ -164,10 +164,10 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)
} }
else else
Py_INCREF(files); Py_INCREF(files);
self->files = files; Py_XSETREF(self->files, files);
/* Transfer reference */ /* Transfer reference */
self->archive = filename; Py_XSETREF(self->archive, filename);
filename = NULL; filename = NULL;
/* Check if there is a prefix directory following the filename. */ /* Check if there is a prefix directory following the filename. */
...@@ -176,7 +176,7 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path) ...@@ -176,7 +176,7 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)
PyUnicode_GET_LENGTH(path)); PyUnicode_GET_LENGTH(path));
if (tmp == NULL) if (tmp == NULL)
goto error; goto error;
self->prefix = tmp; Py_XSETREF(self->prefix, tmp);
if (PyUnicode_READ_CHAR(path, len-1) != SEP) { if (PyUnicode_READ_CHAR(path, len-1) != SEP) {
/* add trailing SEP */ /* add trailing SEP */
tmp = PyUnicode_FromFormat("%U%c", self->prefix, SEP); tmp = PyUnicode_FromFormat("%U%c", self->prefix, SEP);
...@@ -185,8 +185,9 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path) ...@@ -185,8 +185,9 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)
Py_SETREF(self->prefix, tmp); Py_SETREF(self->prefix, tmp);
} }
} }
else else {
self->prefix = PyUnicode_New(0, 0); Py_XSETREF(self->prefix, PyUnicode_New(0, 0));
}
Py_DECREF(path); Py_DECREF(path);
return 0; return 0;
......
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