This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix some memory leaks
- From: Richard Biener <rguenther at suse dot de>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 11 Mar 2015 20:15:13 +0100
- Subject: Re: [PATCH] Fix some memory leaks
- Authentication-results: sourceware.org; auth=none
- References: <20150311190425 dot GP1746 at tucnak dot redhat dot com>
On March 11, 2015 8:04:25 PM CET, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>Valgrind reported some memory leaks. record_builtin_type calls
>just get_identifier on the name, and get_identifier never uses the
>original
>string for storage, it always allocates it on its own, so using xstrdup
>as get_identifier argument leaks the memory.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
Thanks,
Richard.
>2015-03-11 Jakub Jelinek <jakub@redhat.com>
>
> * c-parser.c (c_parse_init): Don't call xstrdup on get_identifier
> argument.
>
> * c-common.c (c_common_nodes_and_builtins): Don't call xstrdup
> on record_builtin_type argument.
>
>--- gcc/c/c-parser.c.jj 2015-02-11 14:39:50.000000000 +0100
>+++ gcc/c/c-parser.c 2015-03-11 16:08:50.282377367 +0100
>@@ -139,7 +139,7 @@ c_parse_init (void)
> /* We always create the symbols but they aren't always supported. */
> char name[50];
> sprintf (name, "__int%d", int_n_data[i].bitsize);
>- id = get_identifier (xstrdup (name));
>+ id = get_identifier (name);
> C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
> C_IS_RESERVED_WORD (id) = 1;
> }
>--- gcc/c-family/c-common.c.jj 2015-03-10 07:37:56.000000000 +0100
>+++ gcc/c-family/c-common.c 2015-03-11 16:11:07.311171401 +0100
>@@ -5458,11 +5458,10 @@ c_common_nodes_and_builtins (void)
> char name[25];
>
> sprintf (name, "__int%d", int_n_data[i].bitsize);
>- record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), xstrdup
>(name),
>+ record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name,
> int_n_trees[i].signed_type);
> sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
>- record_builtin_type (RID_MAX, xstrdup (name),
>- int_n_trees[i].unsigned_type);
>+ record_builtin_type (RID_MAX, name,
>int_n_trees[i].unsigned_type);
> }
>
> if (c_dialect_cxx ())
>
> Jakub