Don’t leak when printf causes wide warnings
authorFather Chrysostomos <sprout@cpan.org>
Fri, 2 Nov 2012 13:17:36 +0000 (06:17 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 2 Nov 2012 13:17:36 +0000 (06:17 -0700)
pp_sys.c
t/op/svleak.t

index 82de0dd..3a034b3 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1515,7 +1515,6 @@ PP(pp_prtf)
 {
     dVAR; dSP; dMARK; dORIGMARK;
     PerlIO *fp;
-    SV *sv = NULL;
 
     GV * const gv
        = (PL_op->op_flags & OPf_STACKED) ? MUTABLE_GV(*++MARK) : PL_defoutgv;
@@ -1554,7 +1553,7 @@ PP(pp_prtf)
        goto just_say_no;
     }
     else {
-       sv = newSV(0);
+       SV *sv = sv_newmortal();
        do_sprintf(sv, SP - MARK, MARK + 1);
        if (!do_print(sv, fp))
            goto just_say_no;
@@ -1563,13 +1562,11 @@ PP(pp_prtf)
            if (PerlIO_flush(fp) == EOF)
                goto just_say_no;
     }
-    SvREFCNT_dec(sv);
     SP = ORIGMARK;
     PUSHs(&PL_sv_yes);
     RETURN;
 
   just_say_no:
-    SvREFCNT_dec(sv);
     SP = ORIGMARK;
     PUSHs(&PL_sv_undef);
     RETURN;
index d3c274f..3e70598 100644 (file)
@@ -15,7 +15,7 @@ BEGIN {
 
 use Config;
 
-plan tests => 44;
+plan tests => 45;
 
 # run some code N times. If the number of SVs at the end of loop N is
 # greater than (N-1)*delta at the end of loop 1, we've got a leak
@@ -308,5 +308,9 @@ leak(2, 0, sub {
     leak(2, 0, sub {
        eval { printf uNopened 42 };
     }, 'printfing to bad handle under fatal warnings does not leak');
-    
+    open my $fh, ">", \my $buf;
+    leak(2, 0, sub {
+       eval { printf $fh chr 2455 };
+    }, 'wide fatal warning does not make printf leak');
+    close $fh or die $!;
 }