diff mbox series

[2/5,libbacktrace] Fix memory leak in build_address_map

Message ID 20181128231617.GA3951@delia
State New
Headers show
Series [1/5,libbacktrace] Factor out backtrace_vector_free | expand

Commit Message

Tom de Vries Nov. 28, 2018, 11:16 p.m. UTC
Hi,

While upon failure in build_address_map we call free_unit_addrs_vector, this
does not actually free the addrs vector, but merely the abbrevs of the units
pointed at by the elements of the addrs vector.

Fix this by adding code to build_address_map to make sure that the addrs vector
is freed upon failure.

Bootstrapped and reg-tested on x86_64.

OK for trunk?

Thanks,
- Tom

[libbacktrace] Fix memory leak in build_address_map

2018-11-28  Tom de Vries  <tdevries@suse.de>

	* dwarf.c (build_address_map): Free addrs vector upon failure.

---
 libbacktrace/dwarf.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Li, Pan2 via Gcc-patches Dec. 27, 2018, 4:26 p.m. UTC | #1
On Wed, Nov 28, 2018 at 3:16 PM Tom de Vries <tdevries@suse.de> wrote:
>
> While upon failure in build_address_map we call free_unit_addrs_vector, this
> does not actually free the addrs vector, but merely the abbrevs of the units
> pointed at by the elements of the addrs vector.
>
> Fix this by adding code to build_address_map to make sure that the addrs vector
> is freed upon failure.
>
> Bootstrapped and reg-tested on x86_64.
>
> OK for trunk?
>
> Thanks,
> - Tom
>
> [libbacktrace] Fix memory leak in build_address_map
>
> 2018-11-28  Tom de Vries  <tdevries@suse.de>
>
>         * dwarf.c (build_address_map): Free addrs vector upon failure.

This is OK.

Thanks.

Ian
diff mbox series

Patch

diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index 13d0aa4bcd8..b818911f5b4 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -1552,6 +1552,11 @@  build_address_map (struct backtrace_state *state, uintptr_t base_address,
  fail:
   free_abbrevs (state, &abbrevs, error_callback, data);
   free_unit_addrs_vector (state, addrs, error_callback, data);
+  if (addrs->count > 0)
+    {
+      backtrace_vector_free (state, &addrs->vec, error_callback, data);
+      addrs->count = 0;
+    }
   return 0;
 }