This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils 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] findtextrel: Don't leak memory in process_file.


When a files do contain textrels we fail to release the segments searched
and valgrind will show:

 2,560 bytes in 16 blocks are definitely lost in loss record 1 of 1
    at 0x40281B5: malloc (in vgpreload_memcheck-x86-linux.so)
    by 0x804AE63: process_file (findtextrel.c:322)
    by 0x804909B: main (findtextrel.c:149)

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 src/ChangeLog     | 4 ++++
 src/findtextrel.c | 1 +
 2 files changed, 5 insertions(+)

diff --git a/src/ChangeLog b/src/ChangeLog
index c9a237a..41e7e73 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
 2015-06-18  Mark Wielaard  <mjw@redhat.com>
 
+	* findtextrel.c (process_file): Free segments after use.
+
+2015-06-18  Mark Wielaard  <mjw@redhat.com>
+
 	* readelf.c (print_phdr): Make sure phdr2_mem lifetime/scope equals
 	phdr2 pointer.
 
diff --git a/src/findtextrel.c b/src/findtextrel.c
index 264a06b..6f1a4b5 100644
--- a/src/findtextrel.c
+++ b/src/findtextrel.c
@@ -484,6 +484,7 @@ cannot get relocation at index %d in section %zu in '%s': %s"),
   if (fd2 != -1)
     close (fd2);
 
+  free (segments);
   tdestroy (knownsrcs, noop);
 
   return result;
-- 
1.8.3.1


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