summaryrefslogtreecommitdiff
path: root/toke.c
diff options
context:
space:
mode:
authorChip Salzenberg <salzench@dun.nielsen.com>1996-02-08 14:18:24 -0500
committerAndy Dougherty <doughera@lafcol.lafayette.edu>1996-02-08 14:18:24 -0500
commit6d5fb7e35ca502ac3801c05dbefda75a40f233d0 (patch)
tree66004779b0cc71567803e233542d8b94433e58ad /toke.c
parent8ba208abf89fdb78c61055f948a484207c04372d (diff)
downloadperl-6d5fb7e35ca502ac3801c05dbefda75a40f233d0.tar.gz
Beta3: Fix for FILE leak when "use" fails
This patch fixes a file leak triggered by "use" or "require" errors. I think it's of fairly high priority...
Diffstat (limited to 'toke.c')
-rw-r--r--toke.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/toke.c b/toke.c
index d24eee9fd9..54c0919aa4 100644
--- a/toke.c
+++ b/toke.c
@@ -44,6 +44,7 @@ static I32 sublex_start _((void));
static int uni _((I32 f, char *s));
#endif
static char * filter_gets _((SV *sv, FILE *fp));
+static void restore_rsfp _((void *f));
/* The following are arranged oddly so that the guard on the switch statement
* can get by with a single comparison (if the compiler is smart enough).
@@ -222,7 +223,7 @@ SV *line;
SAVESPTR(linestr);
SAVEPPTR(lex_brackstack);
SAVEPPTR(lex_casestack);
- SAVESPTR(rsfp);
+ SAVEDESTRUCTOR(restore_rsfp, rsfp);
lex_state = LEX_NORMAL;
lex_defer = 0;
@@ -268,6 +269,19 @@ lex_end()
}
static void
+restore_rsfp(f)
+void *f;
+{
+ FILE *fp = (FILE*)f;
+
+ if (rsfp == stdin)
+ clearerr(rsfp);
+ else if (rsfp != fp)
+ fclose(rsfp);
+ rsfp = fp;
+}
+
+static void
incline(s)
char *s;
{