From: Doug MacEachern Date: Thu, 2 Aug 2001 18:15:22 +0000 (-0700) Subject: [patch] plug PL_origargv leak X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bc0a45ed05a5ed25882d9d65d5140ab818bd1fbf;p=p5sagit%2Fp5-mst-13.2.git [patch] plug PL_origargv leak Message-ID: p4raw-id: //depot/perl@11559 --- diff --git a/perl.c b/perl.c index c5d3313..e6d6f5f 100644 --- a/perl.c +++ b/perl.c @@ -499,6 +499,11 @@ perl_destruct(pTHXx) PL_e_script = Nullsv; } + while (--PL_origargc >= 0) { + Safefree(PL_origargv[PL_origargc]); + } + Safefree(PL_origargv); + /* magical thingies */ SvREFCNT_dec(PL_ofs_sv); /* $, */ @@ -895,8 +900,21 @@ setuid perl scripts securely.\n"); ("__environ", (unsigned long *) &environ_pointer, NULL); #endif /* environ */ - PL_origargv = argv; PL_origargc = argc; + { + /* we copy rather than point to argv + * since perl_clone will copy and perl_destruct + * has no way of knowing if we've made a copy or + * just point to argv + */ + int i = PL_origargc; + New(0, PL_origargv, i+1, char*); + PL_origargv[i] = '\0'; + while (i-- > 0) { + PL_origargv[i] = savepv(argv[i]); + } + } + #ifdef USE_ENVIRON_ARRAY PL_origenviron = environ; #endif