summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2022-07-25 20:23:41 (GMT)
committerGitHub <noreply@github.com>2022-07-25 20:23:41 (GMT)
commit2d26449b06f310d72eb7df58a7133a16d47d30ed (patch)
tree95df743ca52323778ec9b1631d4ceb6788c9f334 /Python
parenta15ae19ffba33282d21440a8fb7c39af26b7d25e (diff)
downloadcpython-2d26449b06f310d72eb7df58a7133a16d47d30ed.zip
cpython-2d26449b06f310d72eb7df58a7133a16d47d30ed.tar.gz
cpython-2d26449b06f310d72eb7df58a7133a16d47d30ed.tar.bz2
gh-94673: Always Finalize Static Builtin Types (#95153)
Static builtin types are finalized by calling _PyStaticType_Dealloc(). Before this change, we were skipping finalizing such a type if it still had subtypes (i.e. its tp_subclasses hadn't been cleared yet). The problem is that types hold several heap objects, which leak if we skip the type's finalization. This change addresses that. For context, there's an old comment (from e9e3eab0b86) that says the following: // If a type still has subtypes, it cannot be deallocated. // A subtype can inherit attributes and methods of its parent type, // and a type must no longer be used once it's deallocated. However, it isn't clear that is actually still true. Clearing tp_dict should mean it isn't a problem. Furthermore, the only subtypes that might still be around come from extension modules that didn't clean them up when unloaded (i.e. extensions that do not implement multi-phase initialization, AKA PEP 489). Those objects are already leaking, so this change doesn't change anything in that regard. Instead, this change means more objects gets cleaned up that before.
Diffstat (limited to 'Python')
-rw-r--r--Python/pylifecycle.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 13efa6f..11a4580 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1672,9 +1672,10 @@ finalize_interp_types(PyInterpreterState *interp)
_PyLong_FiniTypes(interp);
_PyThread_FiniType(interp);
_PyErr_FiniTypes(interp);
- _PyTypes_Fini(interp);
_PyTypes_FiniTypes(interp);
+ _PyTypes_Fini(interp);
+
// Call _PyUnicode_ClearInterned() before _PyDict_Fini() since it uses
// a dict internally.
_PyUnicode_ClearInterned(interp);