From: Marcus Holland-Moritz Date: Thu, 3 Jan 2008 17:07:06 +0000 (+0000) Subject: Fix memory leaks in XS_PerlIO_get_layers() by mortalizing X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1eb9e81d303aab0f6c2386f44bc76241948fce0f;p=p5sagit%2Fp5-mst-13.2.git Fix memory leaks in XS_PerlIO_get_layers() by mortalizing all variables pushed on the stack. Also make sure the loop is using mXPUSHi() and not XPUSHi(). p4raw-id: //depot/perl@32816 --- diff --git a/universal.c b/universal.c index 7fc2ad3..b4f296b 100644 --- a/universal.c +++ b/universal.c @@ -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++; } }