From: Tom Tromey Date: Thu, 31 Oct 2019 16:34:40 +0000 (-0600) Subject: Use unique_xmalloc_ptr in fixup_go_packaging X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=421d1616230a78449dc2f5abb60f03d38b96c3cf;p=binutils-gdb.git Use unique_xmalloc_ptr in fixup_go_packaging 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 * dwarf2read.c (fixup_go_packaging): Use unique_xmalloc_ptr. Change-Id: I0c553d0c6579db478c27bc40fc21133a61e1a4d9 --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ab9aa9fbd69..1472cd4aabd 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2020-01-08 Tom Tromey + + * dwarf2read.c (fixup_go_packaging): Use unique_xmalloc_ptr. + 2020-01-08 Tom Tromey * dwarf2read.c (add_partial_symbol): Use unique_xmalloc_ptr. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 03c27982b18..b2d6136e554 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -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 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 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); } }