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
authorFather Chrysostomos <sprout@cpan.org>
Fri, 7 Jun 2013 15:26:03 +0000 (08:26 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 7 Jun 2013 15:26:40 +0000 (08:26 -0700)
commit9332b95f7fd17b2400da85452a406bc151d30d91
tree7b4f1875a9a35c6afb583bcd778e74061293a8b5
parente987ad1c31f774bda2a3a14929ae1fc88f759ccc
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.
pp.c
t/op/svleak.t