public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix some memory leaks
@ 2015-03-11 19:04 Jakub Jelinek
  2015-03-11 19:15 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2015-03-11 19:04 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

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?

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix some memory leaks
  2015-03-11 19:04 [PATCH] Fix some memory leaks Jakub Jelinek
@ 2015-03-11 19:15 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2015-03-11 19:15 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-11 19:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-11 19:04 [PATCH] Fix some memory leaks Jakub Jelinek
2015-03-11 19:15 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).