Don’t leak when printfing to bad handle under fatal warnings
authorFather Chrysostomos <sprout@cpan.org>
Fri, 2 Nov 2012 13:12:27 +0000 (06:12 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 2 Nov 2012 13:12:27 +0000 (06:12 -0700)
pp_sys.c
t/op/svleak.t

index bb82e32..82de0dd 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1515,7 +1515,7 @@ PP(pp_prtf)
 {
     dVAR; dSP; dMARK; dORIGMARK;
     PerlIO *fp;
-    SV *sv;
+    SV *sv = NULL;
 
     GV * const gv
        = (PL_op->op_flags & OPf_STACKED) ? MUTABLE_GV(*++MARK) : PL_defoutgv;
@@ -1540,7 +1540,6 @@ PP(pp_prtf)
        }
     }
 
-    sv = newSV(0);
     if (!io) {
        report_evil_fh(gv);
        SETERRNO(EBADF,RMS_IFI);
@@ -1555,6 +1554,7 @@ PP(pp_prtf)
        goto just_say_no;
     }
     else {
+       sv = newSV(0);
        do_sprintf(sv, SP - MARK, MARK + 1);
        if (!do_print(sv, fp))
            goto just_say_no;
index 15ffb46..d3c274f 100644 (file)
@@ -15,7 +15,7 @@ BEGIN {
 
 use Config;
 
-plan tests => 43;
+plan tests => 44;
 
 # 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
@@ -301,3 +301,12 @@ leak(2, 0, sub {
        }, "/(?{})\$x/ where \$x is $t does not leak");
     }
 }
+
+
+{
+    use warnings FATAL => 'all';
+    leak(2, 0, sub {
+       eval { printf uNopened 42 };
+    }, 'printfing to bad handle under fatal warnings does not leak');
+    
+}