This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid leaks when calling mg_set() in leave_scope()
authorDavid Mitchell <davem@iabyn.com>
Fri, 11 Dec 2015 12:06:39 +0000 (12:06 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 11 Dec 2015 12:14:57 +0000 (12:14 +0000)
commit2baebb988343167d06d3d536e2de40b4427dc37e
tree8085a6070450a904261fd858ad443d206081a722
parentfacc1dc2646135cef09100080f18ecafbf1df900
avoid leaks when calling mg_set() in leave_scope()

In leave_scope() in places like SAVEt_SV, it does stuff like

    if (SvSMAGICAL(...))
        mg_set(...)
    SvREFCNT_dec_NN(ARG0_SV)

If mg_set() dies (e.g. it calls STORE() and STORE() dies), then ARG0_SV
would leak. Fix this by putting ARG0_SV back in the save stack in this
case.

A similar thing applies to SAVEt_AV and SAVEt_HV, but I couldn't
think of a simple test for those, as tied array and hashes don't have
set magic (just RMG).

Also, SAVEt_AV and SAVEt_HV share a lot of common code, so I made
SAVEt_HV goto into the SAVEt_AV code block for the common part.
scope.c
t/op/svleak.t