Fix memory leaks in XS_PerlIO_get_layers() by mortalizing
authorMarcus Holland-Moritz <mhx-perl@gmx.net>
Thu, 3 Jan 2008 17:07:06 +0000 (17:07 +0000)
committerMarcus Holland-Moritz <mhx-perl@gmx.net>
Thu, 3 Jan 2008 17:07:06 +0000 (17:07 +0000)
all variables pushed on the stack. Also make sure the loop
is using mXPUSHi() and not XPUSHi().

p4raw-id: //depot/perl@32816

universal.c

index 7fc2ad3..b4f296b 100644 (file)
@@ -961,25 +961,25 @@ XS(XS_PerlIO_get_layers)
 
                  if (details) {
                       XPUSHs(namok
-                             ? newSVpvn(SvPVX_const(*namsvp), SvCUR(*namsvp))
+                             ? sv_2mortal(newSVpvn(SvPVX_const(*namsvp), SvCUR(*namsvp)))
                              : &PL_sv_undef);
                       XPUSHs(argok
-                             ? newSVpvn(SvPVX_const(*argsvp), SvCUR(*argsvp))
+                             ? sv_2mortal(newSVpvn(SvPVX_const(*argsvp), SvCUR(*argsvp)))
                              : &PL_sv_undef);
                       if (flgok)
-                           XPUSHi(SvIVX(*flgsvp));
+                           mXPUSHi(SvIVX(*flgsvp));
                       else
                            XPUSHs(&PL_sv_undef);
                       nitem += 3;
                  }
                  else {
                       if (namok && argok)
-                           XPUSHs(Perl_newSVpvf(aTHX_ "%"SVf"(%"SVf")",
+                           XPUSHs(sv_2mortal(Perl_newSVpvf(aTHX_ "%"SVf"(%"SVf")",
                                                 SVfARG(*namsvp),
-                                                SVfARG(*argsvp)));
+                                                SVfARG(*argsvp))));
                       else if (namok)
-                           XPUSHs(Perl_newSVpvf(aTHX_ "%"SVf,
-                                                SVfARG(*namsvp)));
+                           XPUSHs(sv_2mortal(Perl_newSVpvf(aTHX_ "%"SVf,
+                                                SVfARG(*namsvp))));
                       else
                            XPUSHs(&PL_sv_undef);
                       nitem++;
@@ -987,7 +987,7 @@ XS(XS_PerlIO_get_layers)
                            const IV flags = SvIVX(*flgsvp);
 
                            if (flags & PERLIO_F_UTF8) {
-                                XPUSHs(newSVpvs("utf8"));
+                                XPUSHs(sv_2mortal(newSVpvs("utf8")));
                                 nitem++;
                            }
                       }