summaryrefslogtreecommitdiffstats
path: root/usr.bin/sed
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>2004-06-03 22:33:50 +0000
committerbrian <brian@FreeBSD.org>2004-06-03 22:33:50 +0000
commit53a20a543af6dbdf53bd7f9c07113081e47a849c (patch)
tree4e6e0ccb3076b812d103c53ee95060d4e6a5a6cc /usr.bin/sed
parent2837207f16afd70fee442e874ae2e7acda55cc78 (diff)
downloadFreeBSD-src-53a20a543af6dbdf53bd7f9c07113081e47a849c.zip
FreeBSD-src-53a20a543af6dbdf53bd7f9c07113081e47a849c.tar.gz
Plug a file descriptor leak.
When sed is asked to inline-edit files, it forgets to close the temporary file and runs out of descriptors for long command lines (assuming you reset kern.maxfilesperproc to something sane that's less than the number of files passed to sed).
Diffstat (limited to 'usr.bin/sed')
-rw-r--r--usr.bin/sed/main.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index 77c89ae..bb5ffec 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -327,15 +327,21 @@ mf_fgets(SPACE *sp, enum e_spflag spflag)
}
if (infile != NULL) {
fclose(infile);
- if (*oldfname != '\0' &&
- rename(fname, oldfname) != 0) {
- warn("rename()");
- unlink(tmpfname);
- exit(1);
+ if (*oldfname != '\0') {
+ if (rename(fname, oldfname) != 0) {
+ warn("rename()");
+ unlink(tmpfname);
+ exit(1);
+ }
+ *oldfname = '\0';
}
- if (*tmpfname != '\0')
+ if (*tmpfname != '\0') {
+ if (outfile != NULL && outfile != stdout)
+ fclose(outfile);
+ outfile = NULL;
rename(tmpfname, fname);
- *tmpfname = *oldfname = '\0';
+ *tmpfname = '\0';
+ }
outfname = NULL;
}
if (firstfile == 0)
OpenPOWER on IntegriCloud