summaryrefslogtreecommitdiff
path: root/usr.bin/awk/run.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2022-06-03 19:40:57 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2022-06-03 19:40:57 +0000
commit85b7799ea07c7cec372903199173becc6afdbd37 (patch)
treeeb68d79e81b73c164247ce7c46c70d5cd2db328c /usr.bin/awk/run.c
parentc3afe39400d033dd0d7314b134334b2c62fad062 (diff)
Fix a file management memory leak that appears to have been there
since the files array was first initialized with stdin, stdout, and stderr (circa 1992). From Miguel Pineiro Jr.
Diffstat (limited to 'usr.bin/awk/run.c')
-rw-r--r--usr.bin/awk/run.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c
index 1a86cec5fea..860911acc40 100644
--- a/usr.bin/awk/run.c
+++ b/usr.bin/awk/run.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: run.c,v 1.71 2022/01/27 16:58:37 millert Exp $ */
+/* $OpenBSD: run.c,v 1.72 2022/06/03 19:40:56 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -1904,13 +1904,13 @@ static void stdinit(void) /* in case stdin, etc., are not constants */
if (files == NULL)
FATAL("can't allocate file memory for %zu files", nfiles);
files[0].fp = stdin;
- files[0].fname = "/dev/stdin";
+ files[0].fname = tostring("/dev/stdin");
files[0].mode = LT;
files[1].fp = stdout;
- files[1].fname = "/dev/stdout";
+ files[1].fname = tostring("/dev/stdout");
files[1].mode = GT;
files[2].fp = stderr;
- files[2].fname = "/dev/stderr";
+ files[2].fname = tostring("/dev/stderr");
files[2].mode = GT;
}
@@ -2014,8 +2014,7 @@ Cell *closefile(Node **a, int n)
stat = fclose(files[i].fp) == EOF;
if (stat)
WARNING("i/o error occurred closing %s", files[i].fname);
- if (i > 2) /* don't do /dev/std... */
- xfree(files[i].fname);
+ xfree(files[i].fname);
files[i].fname = NULL; /* watch out for ref thru this */
files[i].fp = NULL;
break;