This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make postav and valstr mortal so they're freed soonish
authorTony Cook <tony@develop-help.com>
Tue, 11 Aug 2020 00:46:38 +0000 (10:46 +1000)
committerKarl Williamson <khw@cpan.org>
Mon, 17 Aug 2020 02:17:01 +0000 (20:17 -0600)
these can leak if the value being dumped (or any part of it)
had get magic and that magic throws an exception.

Several other SVs can also leak in that case, but cleaning those up
is more complex.

dist/Data-Dumper/Dumper.xs

index f91145a..d4b34ad 100644 (file)
@@ -1613,12 +1613,13 @@ Data_Dumper_Dumpxs(href, ...)
                         style.sortkeys = &PL_sv_yes;
                }
                postav = newAV();
+                sv_2mortal((SV*)postav);
 
                if (todumpav)
                    imax = av_len(todumpav);
                else
                    imax = -1;
-               valstr = newSVpvs("");
+               valstr = newSVpvs_flags("", SVs_TEMP);
                for (i = 0; i <= imax; ++i) {
                    SV *newapad;
                
@@ -1719,8 +1720,6 @@ Data_Dumper_Dumpxs(href, ...)
                            retval = newSVpvs_flags("", SVs_TEMP);
                    }
                }
-               SvREFCNT_dec(postav);
-               SvREFCNT_dec(valstr);
 
                 /* we defer croaking until here so that temporary SVs and
                  * buffers won't be leaked */