From: Gurusamy Sarathy Date: Mon, 6 Jul 1998 02:59:09 +0000 (+0000) Subject: fix small memleak on -e, don't try to find_script() when e_script X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6c4ab083df0a08a25e458d0861e2ec7909cdb03b;p=p5sagit%2Fp5-mst-13.2.git fix small memleak on -e, don't try to find_script() when e_script p4raw-id: //depot/perl@1331 --- diff --git a/perl.c b/perl.c index 7be4185..7202c87 100644 --- a/perl.c +++ b/perl.c @@ -1900,20 +1900,28 @@ open_script(char *scriptname, bool dosearch, SV *sv, int *fdscript) dTHR; register char *s; - /* scriptname will be non-NULL if find_script() returns */ - scriptname = find_script(scriptname, dosearch, NULL, 1); + *fdscript = -1; - if (strnEQ(scriptname, "/dev/fd/", 8) && isDIGIT(scriptname[8]) ) { - char *s = scriptname + 8; - *fdscript = atoi(s); - while (isDIGIT(*s)) - s++; - if (*s) - scriptname = s + 1; + if (e_script) { + origfilename = savepv("-e"); } - else - *fdscript = -1; - origfilename = (e_script ? savepv("-e") : scriptname); + else { + /* if find_script() returns, it returns a malloc()-ed value */ + origfilename = scriptname = find_script(scriptname, dosearch, NULL, 1); + + if (strnEQ(scriptname, "/dev/fd/", 8) && isDIGIT(scriptname[8]) ) { + char *s = scriptname + 8; + *fdscript = atoi(s); + while (isDIGIT(*s)) + s++; + if (*s) { + scriptname = savepv(s + 1); + Safefree(origfilename); + origfilename = scriptname; + } + } + } + curcop->cop_filegv = gv_fetchfile(origfilename); if (strEQ(origfilename,"-")) scriptname = "";