From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10981 invoked by alias); 9 Feb 2004 21:10:12 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 10970 invoked from network); 9 Feb 2004 21:10:11 -0000 Received: from unknown (HELO nevyn.them.org) (66.93.172.17) by sources.redhat.com with SMTP; 9 Feb 2004 21:10:11 -0000 Received: from drow by nevyn.them.org with local (Exim 4.30 #1 (Debian)) id 1AqIfS-00074C-2Z; Mon, 09 Feb 2004 16:10:10 -0500 Date: Mon, 09 Feb 2004 21:10:00 -0000 From: Daniel Jacobowitz To: carlton@kealia.com, gdb-patches@sources.redhat.com Subject: Avoid obstack_free in cp-namespace.c Message-ID: <20040209211010.GA25073@nevyn.them.org> Mail-Followup-To: carlton@kealia.com, gdb-patches@sources.redhat.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.1i X-SW-Source: 2004-02/txt/msg00207.txt.bz2 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 * 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.