This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Data::Dumper: don't leak the working retval
authorTony Cook <tony@develop-help.com>
Mon, 10 Aug 2020 06:26:30 +0000 (16:26 +1000)
committerKarl Williamson <khw@cpan.org>
Mon, 17 Aug 2020 02:17:01 +0000 (20:17 -0600)
do this by mortalizing the SV on creation, rather than when we
push it on the stack

dist/Data-Dumper/Dumper.xs

index a324cb6..f91145a 100644 (file)
@@ -1541,7 +1541,7 @@ Data_Dumper_Dumpxs(href, ...)
            seenhv = NULL;
            name = sv_newmortal();
        
-           retval = newSVpvs("");
+           retval = newSVpvs_flags("", SVs_TEMP);
            if (SvROK(href)
                && (hv = (HV*)SvRV((SV*)href))
                && SvTYPE(hv) == SVt_PVHV)              {
@@ -1714,9 +1714,9 @@ Data_Dumper_Dumpxs(href, ...)
                    }
                    SvPVCLEAR(valstr);
                    if (gimme == G_ARRAY) {
-                       XPUSHs(sv_2mortal(retval));
+                       XPUSHs(retval);
                        if (i < imax)   /* not the last time thro ? */
-                           retval = newSVpvs("");
+                           retval = newSVpvs_flags("", SVs_TEMP);
                    }
                }
                SvREFCNT_dec(postav);
@@ -1732,7 +1732,7 @@ Data_Dumper_Dumpxs(href, ...)
            else
                croak("Call to new() method failed to return HASH ref");
            if (gimme != G_ARRAY)
-               XPUSHs(sv_2mortal(retval));
+               XPUSHs(retval);
        }
 
 SV *