diff mbox

[2/4] Use unique_xmalloc_ptr in fixup_go_packaging

Message ID 20200107220754.24796-3-tromey@adacore.com
State New
Headers show

Commit Message

Tom Tromey Jan. 7, 2020, 10:07 p.m. UTC
This changes fixup_go_packaging to use unique_xmalloc_ptr.  I kept
this patch separate as it is slightly more complicated than the
previous changes.

gdb/ChangeLog
2020-01-07  Tom Tromey  <tromey@adacore.com>

	* dwarf2read.c (fixup_go_packaging): Use unique_xmalloc_ptr.

Change-Id: I0c553d0c6579db478c27bc40fc21133a61e1a4d9
---
 gdb/ChangeLog    |  4 ++++
 gdb/dwarf2read.c | 16 +++++++---------
 2 files changed, 11 insertions(+), 9 deletions(-)

Comments

Simon Marchi Jan. 8, 2020, 3:46 a.m. UTC | #1
On 2020-01-07 5:07 p.m., Tom Tromey wrote:
> This changes fixup_go_packaging to use unique_xmalloc_ptr.  I kept
> this patch separate as it is slightly more complicated than the
> previous changes.
> 
> gdb/ChangeLog
> 2020-01-07  Tom Tromey  <tromey@adacore.com>
> 
> 	* dwarf2read.c (fixup_go_packaging): Use unique_xmalloc_ptr.
> 
> Change-Id: I0c553d0c6579db478c27bc40fc21133a61e1a4d9

This LGTM.

Simon
diff mbox

Patch

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 9fd2b7715b1..e6584d96537 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -9896,7 +9896,7 @@  compute_delayed_physnames (struct dwarf2_cu *cu)
 static void
 fixup_go_packaging (struct dwarf2_cu *cu)
 {
-  char *package_name = NULL;
+  gdb::unique_xmalloc_ptr<char> package_name;
   struct pending *list;
   int i;
 
@@ -9911,24 +9911,24 @@  fixup_go_packaging (struct dwarf2_cu *cu)
 	  if (sym->language () == language_go
 	      && SYMBOL_CLASS (sym) == LOC_BLOCK)
 	    {
-	      char *this_package_name = go_symbol_package_name (sym);
+	      gdb::unique_xmalloc_ptr<char> this_package_name
+		(go_symbol_package_name (sym));
 
 	      if (this_package_name == NULL)
 		continue;
 	      if (package_name == NULL)
-		package_name = this_package_name;
+		package_name = std::move (this_package_name);
 	      else
 		{
 		  struct objfile *objfile
 		    = cu->per_cu->dwarf2_per_objfile->objfile;
-		  if (strcmp (package_name, this_package_name) != 0)
+		  if (strcmp (package_name.get (), this_package_name.get ()) != 0)
 		    complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
 			       (symbol_symtab (sym) != NULL
 				? symtab_to_filename_for_display
 				    (symbol_symtab (sym))
 				: objfile_name (objfile)),
-			       this_package_name, package_name);
-		  xfree (this_package_name);
+			       this_package_name.get (), package_name.get ());
 		}
 	    }
 	}
@@ -9938,7 +9938,7 @@  fixup_go_packaging (struct dwarf2_cu *cu)
     {
       struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
       const char *saved_package_name
-	= obstack_strdup (&objfile->per_bfd->storage_obstack, package_name);
+	= obstack_strdup (&objfile->per_bfd->storage_obstack, package_name.get ());
       struct type *type = init_type (objfile, TYPE_CODE_MODULE, 0,
 				     saved_package_name);
       struct symbol *sym;
@@ -9953,8 +9953,6 @@  fixup_go_packaging (struct dwarf2_cu *cu)
       SYMBOL_TYPE (sym) = type;
 
       add_symbol_to_list (sym, cu->get_builder ()->get_global_symbols ());
-
-      xfree (package_name);
     }
 }