This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Stop delete local $ENV{foo} from leaking
It was only leaking when the env var did not already exist.
The code in question in pp.c:S_do_delete_local was calling hv_delete
to delete the element, which autovivifies, deletes, and returns a mag-
ical mortal for magical hashes. It was assuming that if a value was
returned the element must have existed, so it was calling SvREFCNT_inc
on the returned mortal to de-mortalize it (since it has to be
restored). Whether the element had existed previously was already
recorded in a bool named ‘preeminent’ (strange name). This variable
should be checked before the SvREFCNT_inc.
I found the same bug in the array code path, potentially affecting
@- and @+, so I fixed it. But I didn’t write a test, as that would
involve a custom regexp engine.