Skip to content

Commit c0cabc2

Browse files
orenmnvstinner
authored andcommitted
bpo-31723: Fix refleaks when zipimporter.__init__() is called more than once (GH-3919)
1 parent 4d3f084 commit c0cabc2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Modules/zipimport.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)
164164
}
165165
else
166166
Py_INCREF(files);
167-
self->files = files;
167+
Py_XSETREF(self->files, files);
168168

169169
/* Transfer reference */
170-
self->archive = filename;
170+
Py_XSETREF(self->archive, filename);
171171
filename = NULL;
172172

173173
/* Check if there is a prefix directory following the filename. */
@@ -176,7 +176,7 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)
176176
PyUnicode_GET_LENGTH(path));
177177
if (tmp == NULL)
178178
goto error;
179-
self->prefix = tmp;
179+
Py_XSETREF(self->prefix, tmp);
180180
if (PyUnicode_READ_CHAR(path, len-1) != SEP) {
181181
/* add trailing SEP */
182182
tmp = PyUnicode_FromFormat("%U%c", self->prefix, SEP);
@@ -185,8 +185,9 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)
185185
Py_SETREF(self->prefix, tmp);
186186
}
187187
}
188-
else
189-
self->prefix = PyUnicode_New(0, 0);
188+
else {
189+
Py_XSETREF(self->prefix, PyUnicode_New(0, 0));
190+
}
190191
Py_DECREF(path);
191192
return 0;
192193

0 commit comments

Comments
 (0)