Use std::string in reread_symbols
authorTom Tromey <tom@tromey.com>
Fri, 18 May 2018 20:30:25 +0000 (14:30 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 21 May 2018 15:38:36 +0000 (09:38 -0600)
This removes a cleanup from reread_symbols by using std::string.  This
fixes a memory leak, because this cleanup is ordinarily discarded, not
run.

Tested by the buildbot.

ChangeLog
2018-05-21  Tom Tromey  <tom@tromey.com>

* symfile.c (reread_symbols): Use std::string for original_name.

gdb/ChangeLog
gdb/symfile.c

index 7f281d477d9e7c453f095e33862e17a931f32362..8c6e5ff4683ccdd7669b7720d863152dda81b405 100644 (file)
@@ -1,3 +1,7 @@
+2018-05-21  Tom Tromey  <tom@tromey.com>
+
+       * symfile.c (reread_symbols): Use std::string for original_name.
+
 2018-05-21  Tom Tromey  <tom@tromey.com>
 
        * dwarf2read.c (dwarf2_read_debug_names): Use std::unique_ptr.
index 1f5d761877558f3d590888ce3a518612ce054e5b..7bc03fbb8f1ebcc90be1c3f63eba374b67773d2c 100644 (file)
@@ -2316,7 +2316,6 @@ reread_symbols (void)
          struct cleanup *old_cleanups;
          struct section_offsets *offsets;
          int num_offsets;
-         char *original_name;
 
          printf_unfiltered (_("`%s' has changed; re-reading symbols.\n"),
                             objfile_name (objfile));
@@ -2382,8 +2381,7 @@ reread_symbols (void)
              error (_("Can't open %s to read symbols."), obfd_filename);
          }
 
-         original_name = xstrdup (objfile->original_name);
-         make_cleanup (xfree, original_name);
+         std::string original_name = objfile->original_name;
 
          /* bfd_openr sets cacheable to true, which is what we want.  */
          if (!bfd_check_format (objfile->obfd, bfd_object))
@@ -2429,8 +2427,9 @@ reread_symbols (void)
          set_objfile_per_bfd (objfile);
 
          objfile->original_name
-           = (char *) obstack_copy0 (&objfile->objfile_obstack, original_name,
-                                     strlen (original_name));
+           = (char *) obstack_copy0 (&objfile->objfile_obstack,
+                                     original_name.c_str (),
+                                     original_name.size ());
 
          /* Reset the sym_fns pointer.  The ELF reader can change it
             based on whether .gdb_index is present, and we need it to
This page took 0.030236 seconds and 4 git commands to generate.