Skip to content

Commit 60587c6

Browse files
committed
Fix refcount leak in finalize_remove_modules()
`PyIter_Next()` returns a new reference, but `finalize_remove_modules()` failed to DECREF `key` when `PyObject_GetItem()`` returns NULL. Fix by DECREF'ing `key` before continuing. Signed-off-by: Yongtao Huang <yongtaoh2022@gamil.com>
1 parent 9b154ab commit 60587c6

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Python/pylifecycle.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ finalize_remove_modules(PyObject *modules, int verbose)
16221622
PyObject *value = PyObject_GetItem(modules, key);
16231623
if (value == NULL) {
16241624
PyErr_FormatUnraisable("Exception ignored while removing modules");
1625+
Py_DECREF(key);
16251626
continue;
16261627
}
16271628
CLEAR_MODULE(key, value);

0 commit comments

Comments
 (0)