From b20ca0bd7fba0743fa97df2d42f6fd3c7b206039 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 23 Dec 2013 23:21:59 +0100 Subject: [PATCH] libdwfl: Fix build_id memory leak in dwfl_segment_report_module. We might already have allocated memory to hold the build_id early in consider_notes when we called consider_phdr for the program headers we've read from the image. We would leak that memory when we don't use it then because we return early/fail. This can be because either we didn't find the correct bias or we skip the module because it would conflict in address space with any already existing module of DWFL. In both cases explicitly free the build_id memory. Signed-off-by: Mark Wielaard --- libdwfl/ChangeLog | 5 +++++ libdwfl/dwfl_segment_report_module.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 8e50f2f2e..807fc2b1e 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2013-12-23 Mark Wielaard + + * dwfl_segment_report_module.c (dwfl_segment_report_module): Free + build_id before returning early. + 2013-12-23 Mark Wielaard * linux-pid-attach.c (__libdwfl_attach_state_for_pid): Report actual diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c index 55f6d3883..fd967e9a3 100644 --- a/libdwfl/dwfl_segment_report_module.c +++ b/libdwfl/dwfl_segment_report_module.c @@ -427,7 +427,10 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, /* We must have seen the segment covering offset 0, or else the ELF header we read at START was not produced by these program headers. */ if (unlikely (!found_bias)) - return finish (); + { + free (build_id); + return finish (); + } /* Now we know enough to report a module for sure: its bounds. */ module_start += bias; @@ -519,7 +522,10 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, } } if (skip_this_module) - return finish (); + { + free (build_id); + return finish (); + } } /* Our return value now says to skip the segments contained -- 2.47.2