From 867ec9d5be8ed8f6d221a1f9689d54aaaf811f22 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sat, 18 Oct 2014 15:57:34 +0000 Subject: plug file descriptor leaks on read or write failure; hinted at by Steffen Nurpmeso . --- read.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'read.c') diff --git a/read.c b/read.c index 4a0ee101..1bcc8cac 100644 --- a/read.c +++ b/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.90 2014/10/12 19:31:41 schwarze Exp $ */ +/* $Id: read.c,v 1.91 2014/10/18 15:57:34 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -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); } -- cgit v1.2.3-56-ge451