Skip to content

Commit c4b1c62

Browse files
authored
Do not hold module in tuple
1 parent 4e83b5b commit c4b1c62

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Python/pylifecycle.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,10 +1560,11 @@ finalize_remove_modules(PyObject *modules, int verbose)
15601560
* elsewhere, keep the referenced module alive
15611561
* until finalize_modules_clear_weaklist() finishes.
15621562
*/ \
1563-
tup = PyTuple_Pack(3, name, wr, mod); \
1563+
Py_INCREF(mod); \
1564+
tup = PyTuple_Pack(3, name, wr, Py_True); \
15641565
} \
15651566
else { \
1566-
tup = PyTuple_Pack(2, name, wr); \
1567+
tup = PyTuple_Pack(3, name, wr, Py_False); \
15671568
} \
15681569
if (!tup || PyList_Append(weaklist, tup) < 0) { \
15691570
PyErr_FormatUnraisable("Exception ignored while removing modules"); \
@@ -1677,6 +1678,9 @@ finalize_modules_clear_weaklist(PyInterpreterState *interp,
16771678
}
16781679
_PyModule_Clear(mod);
16791680
Py_DECREF(mod);
1681+
if (PyTuple_GET_ITEM(tup, 2) == Py_True) {
1682+
Py_DECREF(mod);
1683+
}
16801684
}
16811685
}
16821686

0 commit comments

Comments
 (0)