This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Change buildsym_compunit::comp_dir to be a unique_xmalloc_ptr


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=905eb0e293820ae91941100ebed291a8f74e1f12

commit 905eb0e293820ae91941100ebed291a8f74e1f12
Author: Tom Tromey <tom@tromey.com>
Date:   Sun May 20 10:22:19 2018 -0600

    Change buildsym_compunit::comp_dir to be a unique_xmalloc_ptr
    
    This change buildsym_compunit::comp_dir to be a unique_xmalloc_ptr.
    This is just a small cleanup to remove some manual memory management.
    
    gdb/ChangeLog
    2018-07-16  Tom Tromey  <tom@tromey.com>
    
    	* buildsym.c (~buildsym_compunit): Update.
    	(struct buildsym_compunit) <comp_unit>: Now a unique_xmalloc_ptr.
    	(start_subfile, patch_subfile_names)
    	(end_symtab_with_blockvector): Update.

Diff:
---
 gdb/ChangeLog  |  7 +++++++
 gdb/buildsym.c | 11 +++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index dbfb028..29df4a0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
 2018-07-16  Tom Tromey  <tom@tromey.com>
 
+	* buildsym.c (~buildsym_compunit): Update.
+	(struct buildsym_compunit) <comp_unit>: Now a unique_xmalloc_ptr.
+	(start_subfile, patch_subfile_names)
+	(end_symtab_with_blockvector): Update.
+
+2018-07-16  Tom Tromey  <tom@tromey.com>
+
 	* buildsym.c (struct buildsym_compunit): Add constructor,
 	destructor, initializers.
 	(start_buildsym_compunit): Remove.
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index b693565..b548c52 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -126,7 +126,6 @@ struct buildsym_compunit
 	xfree (subfile->line_vector);
 	xfree (subfile);
       }
-    xfree (comp_dir);
   }
 
   /* The objfile we're reading debug info from.  */
@@ -142,7 +141,7 @@ struct buildsym_compunit
   struct subfile *main_subfile = nullptr;
 
   /* E.g., DW_AT_comp_dir if DWARF.  Space for this is malloc'd.  */
-  char *comp_dir;
+  gdb::unique_xmalloc_ptr<char> comp_dir;
 
   /* Space for this is not malloc'd, and is assumed to have at least
      the same lifetime as objfile.  */
@@ -699,7 +698,7 @@ start_subfile (const char *name)
 
   gdb_assert (buildsym_compunit != NULL);
 
-  subfile_dirname = buildsym_compunit->comp_dir;
+  subfile_dirname = buildsym_compunit->comp_dir.get ();
 
   /* See if this subfile is already registered.  */
 
@@ -820,7 +819,7 @@ patch_subfile_names (struct subfile *subfile, const char *name)
       && subfile->name != NULL
       && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
     {
-      buildsym_compunit->comp_dir = subfile->name;
+      buildsym_compunit->comp_dir.reset (subfile->name);
       subfile->name = xstrdup (name);
       set_last_source_file (name);
 
@@ -1405,10 +1404,10 @@ end_symtab_with_blockvector (struct block *static_block,
   if (buildsym_compunit->comp_dir != NULL)
     {
       /* Reallocate the dirname on the symbol obstack.  */
+      const char *comp_dir = buildsym_compunit->comp_dir.get ();
       COMPUNIT_DIRNAME (cu)
 	= (const char *) obstack_copy0 (&objfile->objfile_obstack,
-					buildsym_compunit->comp_dir,
-					strlen (buildsym_compunit->comp_dir));
+					comp_dir, strlen (comp_dir));
     }
 
   /* Save the debug format string (if any) in the symtab.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]