diff options
| author | Mark Wielaard <[email protected]> | 2015-12-01 23:11:55 +0100 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2016-01-02 20:37:45 +0100 |
| commit | 69d68dd50282469ddc45fc462a2506176b8f3289 (patch) | |
| tree | 99043668ab9453d8e626248e076f3f0da12a791b /libdwfl/link_map.c | |
| parent | 355b408bb9aa49703544fa4086e1ae463737fcf6 (diff) | |
libdwfl: Fix memory leak in link_map.c dwfl_link_map_report.
The phdrs buffer could come from the core file or through the executable.
dwfl_link_map_report would leak the buffer if it came from the executable.
Track where the buffer came from and free appropriately.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'libdwfl/link_map.c')
| -rw-r--r-- | libdwfl/link_map.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c index e73b2195..2bc04006 100644 --- a/libdwfl/link_map.c +++ b/libdwfl/link_map.c @@ -791,6 +791,7 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size, bool in_ok = (*memory_callback) (dwfl, phdr_segndx, &in.d_buf, &in.d_size, phdr, phnum * phent, memory_callback_arg); + bool in_from_exec = false; if (! in_ok && dwfl->user_core != NULL && dwfl->user_core->executable_for_core != NULL) @@ -855,6 +856,7 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size, return false; } in_ok = true; + in_from_exec = true; } if (in_ok) { @@ -903,8 +905,11 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size, } } - (*memory_callback) (dwfl, -1, &in.d_buf, &in.d_size, 0, 0, - memory_callback_arg); + if (in_from_exec) + free (in.d_buf); + else + (*memory_callback) (dwfl, -1, &in.d_buf, &in.d_size, 0, 0, + memory_callback_arg); free (buf); } else |
