SIGN IN SIGN UP

[mypyc] Fix memory leak in `Exception` subclasses with instance attributes (#21719)

Fixes #21716

When mypyc compiles `class Foo(Exception)` with instance attributes, it
staples an extra `__dict__` slot onto the end of the base exception
struct to hold them but it doesn't generate its own dealloc; the type
inherits `BaseException`s, which only frees the base's own fields and
has no idea the extra slot exists, meaning that the dict leaks on every
destruction.


The fix: Flip the gate in `emitclass.py` so we emit our own `tp_dealloc`
/ `tp_clear` / `tp_traverse` for this case too. The existing
builtin-base dealloc path then does the right thing: our clear frees the
extra slot, then the base's dealloc frees the rest.
V
Vaggelis Danias committed
82e8498c19494edebee08dd615470443ec53fffc
Parent: 2e6c87e
Committed by GitHub <noreply@github.com> on 7/15/2026, 10:22:53 AM