* mdocml: plug file descriptor leaks on read or write failure; hinted at
@ 2014-10-18 15:57 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-10-18 15:57 UTC (permalink / raw)
To: source
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-10-18 15:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-18 15:57 mdocml: plug file descriptor leaks on read or write failure; hinted at schwarze
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).