Skip to content
Prev Previous commit
Next Next commit
Do not hold module in tuple
  • Loading branch information
neonene authored Jul 1, 2025
commit c4b1c62ea0dadc164097943c86c6e46181901335
8 changes: 6 additions & 2 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1560,10 +1560,11 @@ finalize_remove_modules(PyObject *modules, int verbose)
* elsewhere, keep the referenced module alive
* until finalize_modules_clear_weaklist() finishes.
*/ \
tup = PyTuple_Pack(3, name, wr, mod); \
Py_INCREF(mod); \
tup = PyTuple_Pack(3, name, wr, Py_True); \
} \
else { \
tup = PyTuple_Pack(2, name, wr); \
tup = PyTuple_Pack(3, name, wr, Py_False); \
} \
if (!tup || PyList_Append(weaklist, tup) < 0) { \
PyErr_FormatUnraisable("Exception ignored while removing modules"); \
Expand Down Expand Up @@ -1677,6 +1678,9 @@ finalize_modules_clear_weaklist(PyInterpreterState *interp,
}
_PyModule_Clear(mod);
Py_DECREF(mod);
if (PyTuple_GET_ITEM(tup, 2) == Py_True) {
Py_DECREF(mod);
}
}
}

Expand Down