From 528e15722bf67d126e17218708c0314bcfadbf6a Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 7 Aug 2018 17:43:08 -0400 Subject: Replace some uses of xstrprintf with string_printf This patch replaces some simple uses of xstrprintf with with string_printf, removing the need to do manual memory freeing. The change in ada-lang.c fixes an apparent memory leak. Regtested on the buildbot. gdb/ChangeLog: * common/filestuff.h (gdb_fopen_cloexec): New overload. (gdb_open_cloexec): Likewise. * nat/linux-osdata.c (command_from_pid): Use string_printf. (commandline_from_pid): Likewise. (linux_xfer_osdata_threads): Likewise. (linux_xfer_osdata_fds): Likewise. * ada-lang.c (is_package_name): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. * breakpoint.c (print_one_breakpoint_location): Use uiout::field_fmt. (print_one_catch_solib): Use string_printf. * coff-pe-read.c (add_pe_exported_sym): Likewise. (add_pe_forwarded_sym): Likewise. * dwarf2read.c (create_type_unit_group): Likewise. (build_error_marker_type): Likewise. * infcall.c (get_function_name): Likewise. * valprint.c (print_converted_chars_to_obstack): Likewise. * xtensa-tdep.c (xtensa_register_type): Likewise. --- gdb/coff-pe-read.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'gdb/coff-pe-read.c') diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c index 97b646a56bd..45f2197ed3a 100644 --- a/gdb/coff-pe-read.c +++ b/gdb/coff-pe-read.c @@ -157,7 +157,6 @@ add_pe_exported_sym (minimal_symbol_reader &reader, const struct read_pe_section_data *section_data, const char *dll_name, struct objfile *objfile) { - char *qualified_name, *bare_name; /* Add the stored offset to get the loaded address of the symbol. */ CORE_ADDR vma = func_rva + section_data->vma_offset; @@ -165,12 +164,14 @@ add_pe_exported_sym (minimal_symbol_reader &reader, of the dll name, e.g. KERNEL32!AddAtomA. This matches the style used by windbg from the "Microsoft Debugging Tools for Windows". */ + std::string bare_name; if (sym_name == NULL || *sym_name == '\0') - bare_name = xstrprintf ("#%d", ordinal); + bare_name = string_printf ("#%d", ordinal); else - bare_name = xstrdup (sym_name); + bare_name = sym_name; - qualified_name = xstrprintf ("%s!%s", dll_name, bare_name); + std::string qualified_name + = string_printf ("%s!%s", dll_name, bare_name.c_str ()); if ((section_data->ms_type == mst_unknown) && debug_coff_pe_read) fprintf_unfiltered (gdb_stdlog , _("Unknown section type for \"%s\"" @@ -178,17 +179,15 @@ add_pe_exported_sym (minimal_symbol_reader &reader, section_data->section_name.c_str (), sym_name, dll_name); - reader.record_with_info (qualified_name, vma, section_data->ms_type, + reader.record_with_info (qualified_name.c_str (), vma, section_data->ms_type, section_data->index); /* Enter the plain name as well, which might not be unique. */ - reader.record_with_info (bare_name, vma, section_data->ms_type, + reader.record_with_info (bare_name.c_str (), vma, section_data->ms_type, section_data->index); if (debug_coff_pe_read > 1) fprintf_unfiltered (gdb_stdlog, _("Adding exported symbol \"%s\"" " in dll \"%s\"\n"), sym_name, dll_name); - xfree (qualified_name); - xfree (bare_name); } /* Create a minimal symbol entry for an exported forward symbol. @@ -209,7 +208,6 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader, CORE_ADDR vma, baseaddr; struct bound_minimal_symbol msymbol; enum minimal_symbol_type msymtype; - char *qualified_name, *bare_name; int forward_dll_name_len = strlen (forward_dll_name); int forward_func_name_len = strlen (forward_func_name); int forward_len = forward_dll_name_len + forward_func_name_len + 2; @@ -254,12 +252,14 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader, of the dll name, e.g. KERNEL32!AddAtomA. This matches the style used by windbg from the "Microsoft Debugging Tools for Windows". */ + std::string bare_name; if (sym_name == NULL || *sym_name == '\0') - bare_name = xstrprintf ("#%d", ordinal); + bare_name = string_printf ("#%d", ordinal); else - bare_name = xstrdup (sym_name); + bare_name = sym_name; - qualified_name = xstrprintf ("%s!%s", dll_name, bare_name); + std::string qualified_name + = string_printf ("%s!%s", dll_name, bare_name.c_str ()); /* Note that this code makes a minimal symbol whose value may point outside of any section in this objfile. These symbols can't @@ -268,12 +268,12 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader, code. */ baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); - reader.record_with_info (qualified_name, vma - baseaddr, msymtype, section); + reader.record_with_info (qualified_name.c_str (), vma - baseaddr, msymtype, + section); /* Enter the plain name as well, which might not be unique. */ - reader.record_with_info (bare_name, vma - baseaddr, msymtype, section); - xfree (qualified_name); - xfree (bare_name); + reader.record_with_info (bare_name.c_str(), vma - baseaddr, msymtype, + section); return 1; } -- cgit v1.2.1