Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@mvista.com>
To: carlton@kealia.com, gdb-patches@sources.redhat.com
Subject: Avoid obstack_free in cp-namespace.c
Date: Mon, 09 Feb 2004 21:10:00 -0000	[thread overview]
Message-ID: <20040209211010.GA25073@nevyn.them.org> (raw)

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.


             reply	other threads:[~2004-02-09 21:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-09 21:10 Daniel Jacobowitz [this message]
2004-02-09 21:20 ` David Carlton
2004-02-09 22:25   ` Daniel Jacobowitz
2004-02-09 22:42 ` Elena Zannoni
2004-02-10  5:44   ` Eli Zaretskii
2004-02-10 17:28     ` Elena Zannoni
2004-02-10 18:55       ` Eli Zaretskii
2004-02-10  5:44 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040209211010.GA25073@nevyn.them.org \
    --to=drow@mvista.com \
    --cc=carlton@kealia.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox