]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-94673: Always Finalize Static Builtin Types (#95153)
authorEric Snow <ericsnowcurrently@gmail.com>
Mon, 25 Jul 2022 20:23:41 +0000 (14:23 -0600)
committerGitHub <noreply@github.com>
Mon, 25 Jul 2022 20:23:41 +0000 (14:23 -0600)
commit2d26449b06f310d72eb7df58a7133a16d47d30ed
tree95df743ca52323778ec9b1631d4ceb6788c9f334
parenta15ae19ffba33282d21440a8fb7c39af26b7d25e
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.
Objects/typeobject.c
Python/pylifecycle.c