Proper fix for the lazy workaround in
7e1774f7
Pure-perl subs return values as mortal copies on the stack, incrementing
the reference count until the next statement. In the case of the last
statement in a sub, that is in the caller, after the other lexicals have
been GCed.
if ( ... ) { ... };
counts as a single statement for this purpose, since it compiles to
( ... ) && do { ... };
The reason this doesn't bite when using XS is that Class::XSAcessor
returns the SV directly from the hash, rather than a mortal copy, so the
reference count never gets incremented.
Generalize the fix to a similar problem (
8e9b9ce5) and pepper potentially
problematic codepaths with explicit NEXTSTATEs. Many of the changes do not
resolve anything as there is no "statement leakage" in most of this code,
but it is a good idea to have them there nevertheless: This way future
code-flow modifications will not accidentally reintroduce this problem.