[PATCH] Fix some memory leaks

2015-03-11 Thread Jakub Jelinek
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  ja...@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.0 +0100
+++ gcc/c/c-parser.c2015-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.0 +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


Re: [PATCH] Fix some memory leaks

2015-03-11 Thread Richard Biener
On March 11, 2015 8:04:25 PM CET, Jakub Jelinek ja...@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  ja...@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.jj2015-02-11 14:39:50.0 +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.0 +0100
+++ gcc/c-family/c-common.c2015-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