This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
stop T_IN/OUT/INOUT/STDIO typemaps leaking
authorDavid Mitchell <davem@iabyn.com>
Fri, 12 Dec 2014 19:52:22 +0000 (19:52 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 12 Dec 2014 19:52:22 +0000 (19:52 +0000)
These typemaps (which are ancient; mostly going back to 1994 or so)
each leaked a GV and an RV.

lib/ExtUtils/typemap

index 0b09641..831baad 100644 (file)
@@ -388,32 +388,48 @@ T_STDIO
        {
            GV *gv = newGVgen("$Package");
            PerlIO *fp = PerlIO_importFILE($var,0);
-           if ( fp && do_open(gv, "+<&", 3, FALSE, 0, 0, fp) )
-               sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1)));
+           if ( fp && do_open(gv, "+<&", 3, FALSE, 0, 0, fp) ) {
+                SV *rv = newRV_noinc((SV*)gv);
+                rv = sv_bless(rv, gv_stashpv("$Package",1));
+               sv_setsv($arg, rv);
+                SvREFCNT_dec_NN(rv);
+            }
            else
                $arg = &PL_sv_undef;
        }
 T_IN
        {
            GV *gv = newGVgen("$Package");
-           if ( do_open(gv, "<&", 2, FALSE, 0, 0, $var) )
-               sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1)));
+           if ( do_open(gv, "<&", 2, FALSE, 0, 0, $var) ) {
+                SV *rv = newRV_noinc((SV*)gv);
+                rv = sv_bless(rv, gv_stashpv("$Package",1));
+               sv_setsv($arg, rv);
+                SvREFCNT_dec_NN(rv);
+            }
            else
                $arg = &PL_sv_undef;
        }
 T_INOUT
        {
            GV *gv = newGVgen("$Package");
-           if ( do_open(gv, "+<&", 3, FALSE, 0, 0, $var) )
-               sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1)));
+           if ( do_open(gv, "+<&", 3, FALSE, 0, 0, $var) ) {
+                SV *rv = newRV_noinc((SV*)gv);
+                rv = sv_bless(rv, gv_stashpv("$Package",1));
+               sv_setsv($arg, rv);
+                SvREFCNT_dec_NN(rv);
+            }
            else
                $arg = &PL_sv_undef;
        }
 T_OUT
        {
            GV *gv = newGVgen("$Package");
-           if ( do_open(gv, "+>&", 3, FALSE, 0, 0, $var) )
-               sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1)));
+           if ( do_open(gv, "+>&", 3, FALSE, 0, 0, $var) ) {
+                SV *rv = newRV_noinc((SV*)gv);
+                rv = sv_bless(rv, gv_stashpv("$Package",1));
+               sv_setsv($arg, rv);
+                SvREFCNT_dec_NN(rv);
+            }
            else
                $arg = &PL_sv_undef;
        }