This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix memory leak in sysinfo

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/
    #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/

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);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]