diff options
author | Mark Lumsden <lum@cvs.openbsd.org> | 2016-09-01 21:06:10 +0000 |
---|---|---|
committer | Mark Lumsden <lum@cvs.openbsd.org> | 2016-09-01 21:06:10 +0000 |
commit | 34b7cd6804cd89693a15a06917f364127925b05c (patch) | |
tree | 1e8cef5a00bb3a87902c20f7436a1845add711f4 /usr.bin | |
parent | 91692d3bbea6b62a01b9e244302342cc9039b4f7 (diff) |
Fix file descriptor leak
Found by Coverity Scan. The ffropen() function returns FIODIR when the
file is a directory. Check return value on error, in case of directory,
close the descriptor.
Source Joachim Nilsson, ok sunil@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mg/extend.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/usr.bin/mg/extend.c b/usr.bin/mg/extend.c index a306256d7d5..db04cea2633 100644 --- a/usr.bin/mg/extend.c +++ b/usr.bin/mg/extend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: extend.c,v 1.63 2015/09/29 02:07:49 guenther Exp $ */ +/* $OpenBSD: extend.c,v 1.64 2016/09/01 21:06:09 lum Exp $ */ /* This file is in the public domain. */ @@ -655,7 +655,7 @@ evalfile(int f, int n) int load(const char *fname) { - int s = TRUE, line; + int s = TRUE, line, ret; int nbytes = 0; char excbuf[128]; FILE *ffp; @@ -664,8 +664,12 @@ load(const char *fname) /* just to be careful */ return (FALSE); - if (ffropen(&ffp, fname, NULL) != FIOSUC) + ret = ffropen(&ffp, fname, NULL); + if (ret != FIOSUC) { + if (ret == FIODIR) + (void)ffclose(ffp, NULL); return (FALSE); + } line = 0; while ((s = ffgetline(ffp, excbuf, sizeof(excbuf) - 1, &nbytes)) |