Use unique_xmalloc_ptr in fixup_go_packaging
authorTom Tromey <tromey@adacore.com>
Thu, 31 Oct 2019 16:34:40 +0000 (10:34 -0600)
committerTom Tromey <tromey@adacore.com>
Wed, 8 Jan 2020 18:17:18 +0000 (11:17 -0700)
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-08  Tom Tromey  <tromey@adacore.com>

* dwarf2read.c (fixup_go_packaging): Use unique_xmalloc_ptr.

Change-Id: I0c553d0c6579db478c27bc40fc21133a61e1a4d9

gdb/ChangeLog
gdb/dwarf2read.c

index ab9aa9fbd69d9cd35857dba945d5bb689937058b..1472cd4aabd028d1d71dcb14bd7244f54bacca18 100644 (file)
@@ -1,3 +1,7 @@
+2020-01-08  Tom Tromey  <tromey@adacore.com>
+
+       * dwarf2read.c (fixup_go_packaging): Use unique_xmalloc_ptr.
+
 2020-01-08  Tom Tromey  <tromey@adacore.com>
 
        * dwarf2read.c (add_partial_symbol): Use unique_xmalloc_ptr.
index 03c27982b184f49fc1f94c623751209a9e0262c8..b2d6136e554eb0f54d61574534530c1f17d53705 100644 (file)
@@ -9892,7 +9892,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;
 
@@ -9907,24 +9907,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 ());
                }
            }
        }
@@ -9934,7 +9934,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;
@@ -9949,8 +9949,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);
     }
 }