This is the mail archive of the
mailing list for the binutils project.
Re: [PATCH] Fix memory leak in sysinfo
- From: Simon Marchi <simon dot marchi at ericsson dot com>
- To: <binutils at sourceware dot org>
- Date: Thu, 1 Jun 2017 23:53:02 +0200
- Subject: Re: [PATCH] Fix memory leak in sysinfo
- Authentication-results: sourceware.org; auth=none
- Authentication-results: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=ericsson.com;
- References: <email@example.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
On 2017-06-01 10:51 PM, Simon Marchi wrote:
> I am trying to build the binutils-gdb repo with address sanitizer, but
> the build fails because sysinfo (executed during the build) leaks, which
> fails its execution and interrupts the Makefile.
> Direct leak of 7122 byte(s) in 755 object(s) allocated from:
> #0 0x7f050664e602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
> #1 0x403bca in yylex /home/emaisin/src/binutils-gdb/binutils/syslex.l:51
> #2 0x4016f9 in yyparse /home/emaisin/build/binutils-gdb/binutils/sysinfo.c:1179
> #3 0x4034b2 in main /home/emaisin/src/binutils-gdb/binutils/sysinfo.y:420
> #4 0x7f050620d82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
> SUMMARY: AddressSanitizer: 7122 byte(s) leaked in 755 allocation(s).
> One solution would have been to find a way to not pass
> -fsanitize=address when building sysinfo, but it's not clear how to omit
> the flag for this program only. It turns out that it was easier to fix
> the leak.
> * sysinfo.y: Free "it" variable.
> binutils/sysinfo.y | 2 ++
> 1 file changed, 2 insertions(+)
> diff --git a/binutils/sysinfo.y b/binutils/sysinfo.y
> index 62758de..6c4a23d 100644
> --- a/binutils/sysinfo.y
> +++ b/binutils/sysinfo.y
> @@ -159,6 +159,8 @@ it:
> case 'c':
> + free (it);
Ah, nevermind, I was actually not rebuilding sysinfo properly: make'ing directly in binutils/
doesn't honor the CFLAGS_FOR_BUILD Makefile variable set in the top-level Makefile. I was
therefore rebuilding without ASan, leading me to think the leak was fixed. But it's not,
NAME is being used at a few other places, and it's not always obvious where it should be freed.