summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-10-18 15:57:34 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-10-18 15:57:34 +0000
commit47f1b2773dddb73cd779684c5e4b8a48464b8bad (patch)
tree17c8132b476046e007da5b1f89016fe4acc2c804 /main.c
parent0f914316c7fac59532818a80b733a10842fb51ee (diff)
downloadmandoc-47f1b2773dddb73cd779684c5e4b8a48464b8bad.tar.gz
plug file descriptor leaks on read or write failure;
hinted at by Steffen Nurpmeso <sdaoden at yandex dot com>.
Diffstat (limited to 'main.c')
-rw-r--r--main.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/main.c b/main.c
index 9e896fd3..2451ff5e 100644
--- a/main.c
+++ b/main.c
@@ -581,14 +581,15 @@ passthrough(const char *file, int fd)
for (off = 0; off < nr; off += nw)
if ((nw = write(STDOUT_FILENO, buf + off,
(size_t)(nr - off))) == -1 || nw == 0) {
+ close(fd);
syscall = "write";
goto fail;
}
- if (nr == 0) {
- close(fd);
+ close(fd);
+
+ if (nr == 0)
return(MANDOCLEVEL_OK);
- }
syscall = "read";
fail: