source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: plug file descriptor leaks on read or write failure; hinted at
Date: Sat, 18 Oct 2014 11:57:34 -0400 (EDT)	[thread overview]
Message-ID: <201410181557.s9IFvYBt006750@krisdoz.my.domain> (raw)

Log Message:
-----------
plug file descriptor leaks on read or write failure;
hinted at by Steffen Nurpmeso <sdaoden at yandex dot com>.

Modified Files:
--------------
    mdocml:
        main.c
        read.c

Revision Data
-------------
Index: read.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/read.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -Lread.c -Lread.c -u -p -r1.90 -r1.91
--- read.c
+++ read.c
@@ -768,7 +768,7 @@ mparse_readfd(struct mparse *curp, int f
 			(*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 f
 	 * 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);
 }
 
Index: main.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.c,v
retrieving revision 1.192
retrieving revision 1.193
diff -Lmain.c -Lmain.c -u -p -r1.192 -r1.193
--- main.c
+++ 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:
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-10-18 15:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201410181557.s9IFvYBt006750@krisdoz.my.domain \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).