re PR middle-end/56461 (GCC is leaking lots of memory)
authorJakub Jelinek <jakub@redhat.com>
Fri, 1 Mar 2013 21:06:04 +0000 (22:06 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 1 Mar 2013 21:06:04 +0000 (22:06 +0100)
PR middle-end/56461
* files.c (_cpp_save_file_entries): Free result at the end.
* pch.c (cpp_string_free): New function.
(cpp_save_state): Use it in htab_create call.
(cpp_write_pch_deps): Free ss->defs.  Destroy ss->definedhash.

From-SVN: r196394

libcpp/ChangeLog
libcpp/files.c
libcpp/pch.c

index 934db6a08cd332793afe97a82ccddfd7ed941630..3d8473dabb6e2f4ba900bb18b0ed0f53558cede2 100644 (file)
@@ -1,3 +1,11 @@
+2013-03-01  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/56461
+       * files.c (_cpp_save_file_entries): Free result at the end.
+       * pch.c (cpp_string_free): New function.
+       (cpp_save_state): Use it in htab_create call.
+       (cpp_write_pch_deps): Free ss->defs.  Destroy ss->definedhash.
+
 2013-02-28  Jakub Jelinek  <jakub@redhat.com>
 
        * files.c (_cpp_find_file): If returning early, before storing
index a614b7cebeddbec6ed750ae851c43331f88b5f6f..dae5526997fb2f7bce8fe8862ffd350baa10979b 100644 (file)
@@ -1771,6 +1771,7 @@ _cpp_save_file_entries (cpp_reader *pfile, FILE *fp)
   struct pchf_data *result;
   size_t result_size;
   _cpp_file *f;
+  bool ret;
 
   for (f = pfile->all_files; f; f = f->next_file)
     ++count;
@@ -1827,7 +1828,9 @@ _cpp_save_file_entries (cpp_reader *pfile, FILE *fp)
   qsort (result->entries, result->count, sizeof (struct pchf_entry),
         pchf_save_compare);
 
-  return fwrite (result, result_size, 1, fp) == 1;
+  ret = fwrite (result, result_size, 1, fp) == 1;
+  free (result);
+  return ret;
 }
 
 /* Read the pchf_data structure from F.  */
index 94e5d21ab7aa6d1312649e6083fe8dbeefc43cc4..6270bda53ed27975ad2a23cdc18a88be68fe1cf8 100644 (file)
@@ -187,6 +187,16 @@ cpp_string_eq (const void *a_p, const void *b_p)
          && memcmp (a->text, b->text, a->len) == 0);
 }
 
+/* Free memory associated with cpp_string.  */
+
+static void
+cpp_string_free (void *a_p)
+{
+  struct cpp_string *a = (struct cpp_string *) a_p;
+  free ((void *) a->text);
+  free (a);
+}
+
 /* Save the current definitions of the cpp_reader for dependency
    checking purposes.  When writing a precompiled header, this should
    be called at the same point in the compilation as cpp_valid_state
@@ -198,7 +208,7 @@ cpp_save_state (cpp_reader *r, FILE *f)
   /* Save the list of non-void identifiers for the dependency checking.  */
   r->savedstate = XNEW (struct cpp_savedstate);
   r->savedstate->definedhash = htab_create (100, cpp_string_hash,
-                                           cpp_string_eq, NULL);
+                                           cpp_string_eq, cpp_string_free);
   cpp_forall_identifiers (r, save_idents, r->savedstate);
 
   /* Write out the list of defined identifiers.  */
@@ -336,6 +346,8 @@ cpp_write_pch_deps (cpp_reader *r, FILE *f)
       return -1;
     }
   free (ss->definedstrs);
+  free (ss->defs);
+  htab_delete (ss->definedhash);
 
   /* Free the saved state.  */
   free (ss);