summaryrefslogtreecommitdiffstats
path: root/read.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 /read.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 'read.c')
-rw-r--r--read.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/read.c b/read.c
index d44fc91e..101c478f 100644
--- a/read.c
+++ b/read.c
@@ -768,7 +768,7 @@ mparse_readfd(struct mparse *curp, int fd, const char *file)
(*curp->mmsg)(MANDOCERR_SYSOPEN,
curp->file_status,
file, 0, 0, strerror(errno));
- goto out;
+ return(curp->file_status);
}
/*
@@ -778,21 +778,19 @@ mparse_readfd(struct mparse *curp, int fd, const char *file)
* the parse phase for the file.
*/
- if ( ! read_whole_file(curp, file, fd, &blk, &with_mmap))
- goto out;
-
- mparse_parse_buffer(curp, blk, file);
-
+ if (read_whole_file(curp, file, fd, &blk, &with_mmap)) {
+ mparse_parse_buffer(curp, blk, file);
#if HAVE_MMAP
- if (with_mmap)
- munmap(blk.buf, blk.sz);
- else
+ if (with_mmap)
+ munmap(blk.buf, blk.sz);
+ else
#endif
- free(blk.buf);
+ free(blk.buf);
+ }
if (STDIN_FILENO != fd && -1 == close(fd))
perror(file);
-out:
+
return(curp->file_status);
}