[v2] solib_target_free_so memory leak

Message ID 20191227124532.5959-1-ssbssa@yahoo.de
State New, archived
Headers

Commit Message

Terekhov, Mikhail via Gdb-patches Dec. 27, 2019, 12:45 p.m. UTC
  gdb/ChangeLog:

2019-12-27  Hannes Domani  <ssbssa@yahoo.de>

	* solib-target.c (struct lm_info_target):
	Change offsets to be a unique_xmalloc_ptr.
	(solib_target_relocate_section_addresses): Update.
---
 gdb/solib-target.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
  

Comments

Tom Tromey Jan. 3, 2020, 4:49 p.m. UTC | #1
>>>>> "Hannes" == Hannes Domani via gdb-patches <gdb-patches@sourceware.org> writes:

Hannes> gdb/ChangeLog:
Hannes> 2019-12-27  Hannes Domani  <ssbssa@yahoo.de>

Hannes> 	* solib-target.c (struct lm_info_target):
Hannes> 	Change offsets to be a unique_xmalloc_ptr.
Hannes> 	(solib_target_relocate_section_addresses): Update.

Thank you.

Hannes> +      li->offsets.reset((struct section_offsets *)

Needs a space before that first open paren.

Hannes> +						    li->offsets.get(),

Likewise.

This is ok with those changes.

Tom
  

Patch

diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index 2b473d6066..549e38cf46 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -46,7 +46,7 @@  struct lm_info_target : public lm_info_base
 
   /* The cached offsets for each section of this shared library,
      determined from SEGMENT_BASES, or SECTION_BASES.  */
-  section_offsets *offsets = NULL;
+  gdb::unique_xmalloc_ptr<section_offsets> offsets;
 };
 
 typedef std::vector<std::unique_ptr<lm_info_target>> lm_info_vector;
@@ -309,9 +309,8 @@  solib_target_relocate_section_addresses (struct so_list *so,
     {
       int num_sections = gdb_bfd_count_sections (so->abfd);
 
-      li->offsets
-	= ((struct section_offsets *)
-	   xzalloc (SIZEOF_N_SECTION_OFFSETS (num_sections)));
+      li->offsets.reset((struct section_offsets *)
+			xzalloc (SIZEOF_N_SECTION_OFFSETS (num_sections)));
 
       if (!li->section_bases.empty ())
 	{
@@ -377,7 +376,8 @@  Could not relocate shared library \"%s\": no segments"), so->so_name);
 	      ULONGEST orig_delta;
 	      int i;
 
-	      if (!symfile_map_offsets_to_segments (so->abfd, data, li->offsets,
+	      if (!symfile_map_offsets_to_segments (so->abfd, data,
+						    li->offsets.get(),
 						    li->segment_bases.size (),
 						    li->segment_bases.data ()))
 		warning (_("\