From: "Wolfgang Müller" <vehk@vehk.de>
To: tech@mandoc.bsd.lv
Subject: read.c does not close gzipped files; leaks memory
Date: Fri, 23 Feb 2018 19:28:10 +0000 [thread overview]
Message-ID: <20180223192810.GA11077@tithonus.olympus> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 361 bytes --]
Hi,
I'm using mandoc on a system with a significant quantity of gzipped
manpages, and noticed its memory usage being unusually high. After
investigating, I found that in read_whole_file, mandoc opens the gzipped
file, but then never closes it before returning from the function.
Find attached a patch which solves this issue.
--
Wolfgang Müller
[-- Attachment #1.2: mandoc-gzleak.patch --]
[-- Type: text/x-diff, Size: 777 bytes --]
--- read.c.orig 2018-02-18 07:27:07.124135724 +0000
+++ read.c 2018-02-18 07:34:02.832965838 +0000
@@ -556,6 +556,7 @@
gzFile gz;
size_t off;
ssize_t ssz;
+ int end;
if (fstat(fd, &st) == -1) {
mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0,
@@ -598,6 +599,7 @@
*with_mmap = 0;
off = 0;
+ end = 0;
fb->sz = 0;
fb->buf = NULL;
for (;;) {
@@ -614,7 +616,8 @@
read(fd, fb->buf + (int)off, fb->sz - off);
if (ssz == 0) {
fb->sz = off;
- return 1;
+ end = 1;
+ break;
}
if (ssz == -1) {
mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0,
@@ -624,6 +627,12 @@
off += (size_t)ssz;
}
+ if (curp->gzip)
+ gzclose(gz);
+
+ if (end)
+ return 1;
+
free(fb->buf);
fb->buf = NULL;
return 0;
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2018-02-23 19:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-23 19:28 Wolfgang Müller [this message]
2018-02-23 22:13 ` Ingo Schwarze
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=20180223192810.GA11077@tithonus.olympus \
--to=vehk@vehk.de \
--cc=tech@mandoc.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).