From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16483 invoked by alias); 9 Mar 2010 18:19:03 -0000 Received: (qmail 16461 invoked by uid 22791); 9 Mar 2010 18:19:00 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,RCVD_IN_DNSWL_HI,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 09 Mar 2010 18:18:52 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o29IIoGp008696 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Mar 2010 13:18:50 -0500 Received: from [10.15.16.55] (toner.yyz.redhat.com [10.15.16.55]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o29IInDE016990; Tue, 9 Mar 2010 13:18:49 -0500 Message-ID: <4B969035.8020906@redhat.com> Date: Tue, 09 Mar 2010 18:19:00 -0000 From: Sami Wagiaalla User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.7) Gecko/20100120 Fedora/3.0.1-1.fc12 Lightning/1.0b1 Thunderbird/3.0.1 MIME-Version: 1.0 To: Tom Tromey CC: GDB Patches Subject: Re: [patch] Fix using_directive memory leak pr 11236 References: <4B8ECACA.9010504@redhat.com> <4B9525DC.3000900@redhat.com> In-Reply-To: Content-Type: multipart/mixed; boundary="------------040907000909040204060204" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-03/txt/msg00360.txt.bz2 This is a multi-part message in MIME format. --------------040907000909040204060204 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 6507 > > Sami> if (strcmp (current->import_src, src) == 0 > Sami> -&& strcmp (current->import_dest, dest) == 0) > Sami> +&& strcmp (current->import_dest, dest) == 0 > Sami> +&& ((!alias&& !current->alias) > Sami> + || strcmp (current->alias, alias) == 0)) > > I think this test is still wrong. > Totally missed that :) Here is a corrected patch: 2010-03-09 Sami Wagiaalla PR C++/11236: * cp-namespace.c (cp_add_using): Deleted. (cp_add_using_directive): Use obstack allocations. Merged the function cp_add_using into this one. Added 'struct obstack *' argument. (cp_scan_for_anonymous_namespaces): Updated. * cp-support.h: Updated. * dwarf2read.c (read_import_statement): Updated. (read_namespace): Updated. diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 5e894d4..7593475 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -117,7 +117,8 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol) anonymous namespace. So add symbols in it to the namespace given by the previous component if there is one, or to the global namespace if there isn't. */ - cp_add_using_directive (dest, src, NULL); + cp_add_using_directive (dest, src, NULL, + &SYMBOL_SYMTAB (symbol)->objfile->objfile_obstack); } /* The "+ 2" is for the "::". */ previous_component = next_component + 2; @@ -128,11 +129,18 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol) } } -/* Add a using directive to using_list. If the using directive in question - has already been added, don't add it twice. */ + +/* Add a using directive to using_directives. If the using directive in + question has already been added, don't add it twice. + Create a new struct using_direct which imports the namespace SRC into the + scope DEST. ALIAS is the name of the imported namespace in the current + scope. If ALIAS is NULL then the namespace is known by its original name. + The arguments are copied into newly allocated memory so they can be + temporaries. */ void -cp_add_using_directive (const char *dest, const char *src, const char *alias) +cp_add_using_directive (const char *dest, const char *src, const char *alias, + struct obstack *obstack) { struct using_direct *current; struct using_direct *new; @@ -142,12 +150,23 @@ cp_add_using_directive (const char *dest, const char *src, const char *alias) for (current = using_directives; current != NULL; current = current->next) { if (strcmp (current->import_src, src) == 0 - && strcmp (current->import_dest, dest) == 0) + && strcmp (current->import_dest, dest) == 0 + && ((alias == NULL && current->alias == NULL) + || (alias != NULL && current->alias != NULL + && strcmp (alias, current->alias) == 0))) return; } - using_directives = cp_add_using (dest, src, alias, using_directives); + new = OBSTACK_ZALLOC (obstack, struct using_direct); + new->import_src = obsavestring (src, strlen (src), obstack); + new->import_dest = obsavestring (dest, strlen (dest), obstack); + + if (alias != NULL) + new->alias = obsavestring (alias, strlen (alias), obstack); + + new->next = using_directives; + using_directives = new; } /* Record the namespace that the function defined by SYMBOL was @@ -198,36 +217,6 @@ cp_is_anonymous (const char *namespace) != NULL); } -/* Create a new struct using direct which imports the namespace SRC into the - scope DEST. ALIAS is the name of the imported namespace in the current - scope. If ALIAS is NULL then the namespace is known by its original name. - Set its next member in the linked list to NEXT; allocate all memory - using xmalloc. It copies the strings, so NAME can be a temporary - string. */ - -struct using_direct * -cp_add_using (const char *dest, - const char *src, - const char *alias, - struct using_direct *next) -{ - struct using_direct *retval; - - retval = xmalloc (sizeof (struct using_direct)); - retval->import_src = savestring (src, strlen(src)); - retval->import_dest = savestring (dest, strlen(dest)); - - if (alias != NULL) - retval->alias = savestring (alias, strlen (alias)); - else - retval->alias = NULL; - - retval->next = next; - retval->searched = 0; - - return retval; -} - /* The C++-specific version of name lookup for static and global names. This makes sure that names get looked for in all namespaces that are in scope. NAME is the natural name of the symbol that diff --git a/gdb/cp-support.h b/gdb/cp-support.h index a6a9af1..3921a5f 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -90,12 +90,8 @@ extern int cp_is_anonymous (const char *namespace); extern void cp_add_using_directive (const char *dest, const char *src, - const char *alias); - -extern struct using_direct *cp_add_using (const char *dest, - const char *src, - const char *alias, - struct using_direct *next); + const char *alias, + struct obstack *obstack); extern void cp_initialize_namespace (void); diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index a05c946..447424e 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -3462,10 +3462,10 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu) strcpy (canonical_name, imported_name); } - using_directives = cp_add_using (import_prefix, - canonical_name, - import_alias, - using_directives); + cp_add_using_directive (import_prefix, + canonical_name, + import_alias, + &cu->objfile->objfile_obstack); } static void @@ -5624,7 +5624,8 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu) if (is_anonymous) { const char *previous_prefix = determine_prefix (die, cu); - cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL); + cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, + &objfile->objfile_obstack); } } --------------040907000909040204060204 Content-Type: text/plain; name="memoryleak.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="memoryleak.patch" Content-length: 6131 2010-03-09 Sami Wagiaalla PR C++/11236: * cp-namespace.c (cp_add_using): Deleted. (cp_add_using_directive): Use obstack allocations. Merged the function cp_add_using into this one. Added 'struct obstack *' argument. (cp_scan_for_anonymous_namespaces): Updated. * cp-support.h: Updated. * dwarf2read.c (read_import_statement): Updated. (read_namespace): Updated. diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 5e894d4..7593475 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -117,7 +117,8 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol) anonymous namespace. So add symbols in it to the namespace given by the previous component if there is one, or to the global namespace if there isn't. */ - cp_add_using_directive (dest, src, NULL); + cp_add_using_directive (dest, src, NULL, + &SYMBOL_SYMTAB (symbol)->objfile->objfile_obstack); } /* The "+ 2" is for the "::". */ previous_component = next_component + 2; @@ -128,11 +129,18 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol) } } -/* Add a using directive to using_list. If the using directive in question - has already been added, don't add it twice. */ + +/* Add a using directive to using_directives. If the using directive in + question has already been added, don't add it twice. + Create a new struct using_direct which imports the namespace SRC into the + scope DEST. ALIAS is the name of the imported namespace in the current + scope. If ALIAS is NULL then the namespace is known by its original name. + The arguments are copied into newly allocated memory so they can be + temporaries. */ void -cp_add_using_directive (const char *dest, const char *src, const char *alias) +cp_add_using_directive (const char *dest, const char *src, const char *alias, + struct obstack *obstack) { struct using_direct *current; struct using_direct *new; @@ -142,12 +150,23 @@ cp_add_using_directive (const char *dest, const char *src, const char *alias) for (current = using_directives; current != NULL; current = current->next) { if (strcmp (current->import_src, src) == 0 - && strcmp (current->import_dest, dest) == 0) + && strcmp (current->import_dest, dest) == 0 + && ((alias == NULL && current->alias == NULL) + || (alias != NULL && current->alias != NULL + && strcmp (alias, current->alias) == 0))) return; } - using_directives = cp_add_using (dest, src, alias, using_directives); + new = OBSTACK_ZALLOC (obstack, struct using_direct); + new->import_src = obsavestring (src, strlen (src), obstack); + new->import_dest = obsavestring (dest, strlen (dest), obstack); + + if (alias != NULL) + new->alias = obsavestring (alias, strlen (alias), obstack); + + new->next = using_directives; + using_directives = new; } /* Record the namespace that the function defined by SYMBOL was @@ -198,36 +217,6 @@ cp_is_anonymous (const char *namespace) != NULL); } -/* Create a new struct using direct which imports the namespace SRC into the - scope DEST. ALIAS is the name of the imported namespace in the current - scope. If ALIAS is NULL then the namespace is known by its original name. - Set its next member in the linked list to NEXT; allocate all memory - using xmalloc. It copies the strings, so NAME can be a temporary - string. */ - -struct using_direct * -cp_add_using (const char *dest, - const char *src, - const char *alias, - struct using_direct *next) -{ - struct using_direct *retval; - - retval = xmalloc (sizeof (struct using_direct)); - retval->import_src = savestring (src, strlen(src)); - retval->import_dest = savestring (dest, strlen(dest)); - - if (alias != NULL) - retval->alias = savestring (alias, strlen (alias)); - else - retval->alias = NULL; - - retval->next = next; - retval->searched = 0; - - return retval; -} - /* The C++-specific version of name lookup for static and global names. This makes sure that names get looked for in all namespaces that are in scope. NAME is the natural name of the symbol that diff --git a/gdb/cp-support.h b/gdb/cp-support.h index a6a9af1..3921a5f 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -90,12 +90,8 @@ extern int cp_is_anonymous (const char *namespace); extern void cp_add_using_directive (const char *dest, const char *src, - const char *alias); - -extern struct using_direct *cp_add_using (const char *dest, - const char *src, - const char *alias, - struct using_direct *next); + const char *alias, + struct obstack *obstack); extern void cp_initialize_namespace (void); diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index a05c946..447424e 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -3462,10 +3462,10 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu) strcpy (canonical_name, imported_name); } - using_directives = cp_add_using (import_prefix, - canonical_name, - import_alias, - using_directives); + cp_add_using_directive (import_prefix, + canonical_name, + import_alias, + &cu->objfile->objfile_obstack); } static void @@ -5624,7 +5624,8 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu) if (is_anonymous) { const char *previous_prefix = determine_prefix (die, cu); - cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL); + cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, + &objfile->objfile_obstack); } } --------------040907000909040204060204--