NetBSD Problem Report #51040
From www@NetBSD.org Sun Apr 3 10:54:57 2016
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id 411DD7A48B
for <gnats-bugs@gnats.NetBSD.org>; Sun, 3 Apr 2016 10:54:57 +0000 (UTC)
Message-Id: <20160403105456.1590B7AA98@mollari.NetBSD.org>
Date: Sun, 3 Apr 2016 10:54:56 +0000 (UTC)
From: er.abhinav.upadhyay@gmail.com
Reply-To: er.abhinav.upadhyay@gmail.com
To: gnats-bugs@NetBSD.org
Subject: Fix memory leak in makemandb(8)
X-Send-Pr-Version: www-1.0
>Number: 51040
>Category: bin
>Synopsis: Fix memory leak in makemandb(8)
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Apr 03 10:55:00 +0000 2016
>Closed-Date: Wed Apr 13 07:53:30 +0000 2016
>Last-Modified: Wed Apr 13 07:53:30 +0000 2016
>Originator: Abhinav Upadhyay
>Release: CURRENT
>Organization:
>Environment:
>Description:
As per the libarchive(3) man page, we should call archive_read_finish(3) once we are done reading the stream in order to free up the resources allocated by libarchive. archive_read_finish(3) implicitly calls archive_read_close(3) if it was not called manually.
In makemandb(8) only archive_read_close(3) is called inside the read_and_decompress function, I think it would result in memory leakage.
The attached patch should fix it.
>How-To-Repeat:
>Fix:
Index: makemandb.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/makemandb/makemandb.c,v
retrieving revision 1.33
diff -u -r1.33 makemandb.c
--- makemandb.c 31 Mar 2016 20:17:58 -0000 1.33
+++ makemandb.c 3 Apr 2016 10:51:33 -0000
@@ -702,7 +702,7 @@
for (;;) {
r = archive_read_data(a, buf + off, *len - off);
if (r == ARCHIVE_OK) {
- archive_read_close(a);
+ archive_read_finish(a);
*bufp = buf;
*len = off;
return 0;
@@ -718,7 +718,7 @@
if (mflags.verbosity)
warnx("File too large: %s", file);
free(buf);
- archive_read_close(a);
+ archive_read_finish(a);
return -1;
}
buf = erealloc(buf, *len);
@@ -727,7 +727,7 @@
archive_error:
warnx("Error while reading `%s': %s", file, archive_error_string(a));
- archive_read_close(a);
+ archive_read_finish(a);
return -1;
}
>Release-Note:
>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51040 CVS commit: src/usr.sbin/makemandb
Date: Tue, 12 Apr 2016 21:41:18 -0400
Module Name: src
Committed By: christos
Date: Wed Apr 13 01:41:18 UTC 2016
Modified Files:
src/usr.sbin/makemandb: makemandb.c
Log Message:
PR/51040: Abhinav Upadhyay: Fix memory leak
To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/usr.sbin/makemandb/makemandb.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: wiz@NetBSD.org
State-Changed-When: Wed, 13 Apr 2016 07:53:30 +0000
State-Changed-Why:
Committed by christos, thanks!
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.