This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid leak with local $h{foo}, $a[n]
authorDavid Mitchell <davem@iabyn.com>
Tue, 26 Mar 2019 11:04:07 +0000 (11:04 +0000)
committerDavid Mitchell <davem@iabyn.com>
Tue, 26 Mar 2019 11:04:07 +0000 (11:04 +0000)
commit85df897fcfe76250deecfdeb239ba1e4279d8532
tree1fe9fab2b7e111409d71b3f052c36b6c87975302
parent657ed7c1c190e7fad1bac2979944d07245bbeea4
avoid leak with local $h{foo}, $a[n]

When SAVEt_DELETE / SAVEt_ADELETE deletes a hash/array entry on scope
exit, they also decrement the refcount of the hash/array, and for the
hash, also free the saved key.

However, if the call to hv_delete() or av_delete() dies (e.g. when
calling a tied DELETE method) then the hash/array and key will leak
because leave_scope() calls av/hv_delete(), *then* does the
SvREFCNT_dec() etc.

The fix is to push new FREEPV/FREESV actions just before calling
av/hv_delete().
scope.c
t/op/tie.t