Bug 21281 - ASAN detects memory leak in sysinfo.c
Summary: ASAN detects memory leak in sysinfo.c
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.29
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 21282 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-03-21 05:57 UTC by Thuan Pham
Modified: 2017-03-22 07:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thuan Pham 2017-03-21 05:57:01 UTC
Dear all,
I would like to report a potential memory leak in Binutils' sysinfo utility which prevents us from compiling the toolset with ASAN.

I face the issue on Ubuntu 64-bit 14.04 and Binutils version is

commit 09220eae9df07c40d206a35e6caaecba92ab8f46
Author: GDB Administrator <gdbadmin@sourceware.org>
Date:   Tue Mar 21 00:00:24 2017 +0000

    Automatic date update in version.in

I configured and compiled Binutils using the following commands using clang-3.5
mkdir build-asan; cd build-asan
CC=clang CFLAGS="-DFORTIFY_SOURCE=2 -fstack-protector-all -fsanitize=undefined,address -fno-omit-frame-pointer -g -Wno-error" ../configure --disable-shared --disable-gdb --disable-libdecnumber --disable-readline --disable-sim
make clean all

Here is the error message I got:
=================================================================
==92396==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 7122 byte(s) in 755 object(s) allocated from:
    #0 0x49c29b in __interceptor_malloc (/home/ubuntu/subjects/binutils-newest/build-asan/binutils/sysinfo+0x49c29b)
    #1 0x4c7161 in yylex /home/ubuntu/subjects/binutils-newest/build-asan/binutils/../../binutils/syslex.l:51:13
    #2 0x4bb13c in yyparse /home/ubuntu/subjects/binutils-newest/build-asan/binutils/sysinfo.c:1177:16
    #3 0x4c4c05 in main /home/ubuntu/subjects/binutils-newest/build-asan/binutils/../../binutils/sysinfo.y:420:3
    #4 0x2b604a4def44 in __libc_start_main /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:287

SUMMARY: AddressSanitizer: 7122 byte(s) leaked in 755 allocation(s).

Regards,
Thuan
Comment 1 Nick Clifton 2017-03-21 10:23:51 UTC
Hi Thuan,

> I would like to report a potential memory leak in Binutils' sysinfo utility
> which prevents us from compiling the toolset with ASAN.

I looked into this a while ago.  In the end though I decided that fixing the leaks was likely to introduce more bugs, and that it just was not worth it for such a minor file.  The leaks are just too small to be worth worrying about.  Instead I set the ASAN_OPTIONS environment variable to ignore the leaks:

  setenv ASAN_OPTIONS "detect_leaks=false"
or
  export ASAN_OPTIONS="detect_leaks=false"  if you use bash...

Cheers
  Nick
Comment 2 Mike Frysinger 2017-03-22 06:08:30 UTC
*** Bug 21282 has been marked as a duplicate of this bug. ***
Comment 3 Mike Frysinger 2017-03-22 06:10:59 UTC
fwiw, ASAN provides '__SANITIZE_ADDRESS__' defines if we wanted to throw random free() calls around, although not sure that'd help in this particular case.
Comment 4 Thuan Pham 2017-03-22 07:35:51 UTC
Hi Nick,
Thank you. Your suggestion resolves the reported issue.
Cheers,
Thuan