[binutils-gdb] Re: asan: more readelf leaks

Alan Modra amodra@sourceware.org
Sat Mar 14 09:54:19 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1bd6175ae79099173c1510d209ad9978129e22c0

commit 1bd6175ae79099173c1510d209ad9978129e22c0
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Mar 14 18:58:11 2020 +1030

    Re: asan: more readelf leaks
    
    In git commit fd486f32d15e I put some static variables used by
    get_symbol_for_build_attribute in a file scope ba_cache struct.  This
    was to prevent leaks in get_symbol_for_build_attribute, and to tidy up
    before readelf exited.  The patch wasn't quite right though.  When
    readelf processes more than one file it was possible to double free
    arrays allocated in get_symbol_for_build_attribute.
    
            * readelf.c (process_file): Clean ba_cache.

Diff:
---
 binutils/ChangeLog | 4 ++++
 binutils/readelf.c | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 5101b8c9912..5f8af946804 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,7 @@
+2020-03-14  Alan Modra  <amodra@gmail.com>
+
+	* readelf.c (process_file): Clean ba_cache.
+
 2020-03-14  Alan Modra  <amodra@gmail.com>
 
 	* elfcomm.h (setup_archive): Update prototype.
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 0f8a0809c55..49eb20f28c3 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -20571,7 +20571,9 @@ process_file (char * file_name)
   free (filedata);
 
   free (ba_cache.strtab);
+  ba_cache.strtab = NULL;
   free (ba_cache.symtab);
+  ba_cache.symtab = NULL;
   ba_cache.filedata = NULL;
 
   return ret;


More information about the Binutils-cvs mailing list