This is the mail archive of the gdb-patches@sources.redhat.com 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]

Avoid obstack_free in cp-namespace.c


Hi David,

What do you think of this change?  It makes the assumption that
lookup_block_symbol will not allocate anything on the objfile obstack, which
is no longer true in a patch I'm testing.  I really dislike obstack_free for
this exact reason.

[For the curious I've audited the remaining uses of obstack_free in GDB. 
The ones in jv-lang.c and stabsread.c are suspicious but seem to be OK, and
the rest are fine except for this one - they release whole obstacks.]

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2004-02-09  Daniel Jacobowitz  <drow@mvista.com>

	* cp-namespace.c (check_one_possible_namespace_symbol): Don't use
	obstack_free.

Index: cp-namespace.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/cp-namespace.c,v
retrieving revision 1.11
diff -u -p -r1.11 cp-namespace.c
--- cp-namespace.c	7 Feb 2004 23:13:47 -0000	1.11
+++ cp-namespace.c	9 Feb 2004 21:03:31 -0000
@@ -783,14 +783,20 @@ check_one_possible_namespace_symbol (con
 				     struct objfile *objfile)
 {
   struct block *block = get_possible_namespace_block (objfile);
-  char *name_copy = obsavestring (name, len, &objfile->objfile_obstack);
-  struct symbol *sym = lookup_block_symbol (block, name_copy, NULL,
-					    VAR_DOMAIN);
+  char *name_copy = alloca (len + 1);
+  struct symbol *sym;
+
+  memcpy (name_copy, name, len);
+  name_copy[len] = '\0';
+  sym = lookup_block_symbol (block, name_copy, NULL, VAR_DOMAIN);
 
   if (sym == NULL)
     {
-      struct type *type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
-				     name_copy, objfile);
+      struct type *type;
+      name_copy = obsavestring (name, len, &objfile->objfile_obstack);
+
+      type = init_type (TYPE_CODE_NAMESPACE, 0, 0, name_copy, objfile);
+
       TYPE_TAG_NAME (type) = TYPE_NAME (type);
 
       sym = obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
@@ -806,11 +812,7 @@ check_one_possible_namespace_symbol (con
       return 0;
     }
   else
-    {
-      obstack_free (&objfile->objfile_obstack, name_copy);
-
-      return 1;
-    }
+    return 1;
 }
 
 /* Look for a symbol named NAME in all the possible namespace blocks.


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