From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47600 invoked by alias); 29 Aug 2019 15:52:09 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 47591 invoked by uid 89); 29 Aug 2019 15:52:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.3 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy= X-Spam-Status: No, score=-23.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Aug 2019 15:52:07 +0000 Received: from librem.wildebeest.org (unknown [145.15.244.12]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 80F2D30278C7; Thu, 29 Aug 2019 17:52:05 +0200 (CEST) Received: by librem.wildebeest.org (Postfix, from userid 1000) id 55D4AC01AC; Thu, 29 Aug 2019 17:52:04 +0200 (CEST) Date: Thu, 29 Aug 2019 15:52:00 -0000 From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Omar Sandoval Subject: Re: Buildbot failure in Wildebeest Builder on whole buildset Message-ID: <20190829155204.GD2622@wildebeest.org> References: <20190829135907.B7CF8802218@builder.wildebeest.org> <6a68b39bec00c8a2e6929f07083320e47ebeb2ca.camel@klomp.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="E39vaYmALEf/7YXx" Content-Disposition: inline In-Reply-To: <6a68b39bec00c8a2e6929f07083320e47ebeb2ca.camel@klomp.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2019-q3/txt/msg00165.txt.bz2 --E39vaYmALEf/7YXx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 495 On Thu, Aug 29, 2019 at 04:23:24PM +0200, Mark Wielaard wrote: > I am replacing some of the self test files with smaller > executables/libraries as attached. Hopefully that will reduce the make > check runtime under valgrind so builder don't time out. That was interesting. It did bring down the make check times under valgrind. But it also showed a memory leak in eu-nm! Triggered by chance because we use different self-check binaries now :) Fix attached and pushed to master. Cheers, Mark --E39vaYmALEf/7YXx Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-nm-Fix-latent-memory-leak-in-show_symbols.patch" Content-length: 1787 >From df33285b60290fadefd140ee2fe616f750105d2f Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 29 Aug 2019 17:46:52 +0200 Subject: [PATCH] nm: Fix latent memory leak in show_symbols. If there are just a handful of symbols then memory for them is allocated on the stack, otherwise the memory is malloced. So before freeing the memory we need to check the number of entries to know if the memory was heap allocated or not. But since not all entries might be used we might have decreased the number of entries to the number we will actually show. Remember the original symbol entries to not have a memory leak. Signed-off-by: Mark Wielaard --- src/ChangeLog | 5 +++++ src/nm.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index aeb62328..cb64f7d9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2019-08-26 Mark Wielaard + + * nm.c (show_symbols): Remember nentries_orig and check before + freeing sym_mem. + 2019-07-05 Omar Sandoval * Makefile.am: Remove -ldl. diff --git a/src/nm.c b/src/nm.c index da1350b4..7f6cf2a2 100644 --- a/src/nm.c +++ b/src/nm.c @@ -1438,6 +1438,7 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehdr *ehdr, free (demangle_buffer); #endif /* Now we know the exact number. */ + size_t nentries_orig = nentries; nentries = nentries_used; /* Sort the entries according to the users wishes. */ @@ -1472,7 +1473,7 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehdr *ehdr, } /* Free all memory. */ - if (nentries * sizeof (sym_mem[0]) >= MAX_STACK_ALLOC) + if (nentries_orig * sizeof (sym_mem[0]) >= MAX_STACK_ALLOC) free (sym_mem); obstack_free (&whereob, NULL); -- 2.20.1 --E39vaYmALEf/7YXx--