bpo-31723: Fix refleaks when zipimporter.init() is called more th… · python/cpython@c0cabc2 (original) (raw)

Original file line number Diff line number Diff line change
@@ -164,10 +164,10 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)
164 164 }
165 165 else
166 166 Py_INCREF(files);
167 -self->files = files;
167 +Py_XSETREF(self->files, files);
168 168
169 169 /* Transfer reference */
170 -self->archive = filename;
170 +Py_XSETREF(self->archive, filename);
171 171 filename = NULL;
172 172
173 173 /* Check if there is a prefix directory following the filename. */
@@ -176,7 +176,7 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)
176 176 PyUnicode_GET_LENGTH(path));
177 177 if (tmp == NULL)
178 178 goto error;
179 -self->prefix = tmp;
179 +Py_XSETREF(self->prefix, tmp);
180 180 if (PyUnicode_READ_CHAR(path, len-1) != SEP) {
181 181 /* add trailing SEP */
182 182 tmp = PyUnicode_FromFormat("%U%c", self->prefix, SEP);
@@ -185,8 +185,9 @@ zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)
185 185 Py_SETREF(self->prefix, tmp);
186 186 }
187 187 }
188 -else
189 -self->prefix = PyUnicode_New(0, 0);
188 +else {
189 +Py_XSETREF(self->prefix, PyUnicode_New(0, 0));
190 + }
190 191 Py_DECREF(path);
191 192 return 0;
192 193