* [PATCH] Fix libcpp PCH related memory leaks (PR middle-end/56461)
@ 2013-03-01 20:17 Jakub Jelinek
2013-03-01 21:03 ` Tom Tromey
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2013-03-01 20:17 UTC (permalink / raw)
To: Tom Tromey; +Cc: gcc-patches
Hi!
This patch fixes various memory leaks in libcpp during PCH writing.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
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.
--- libcpp/files.c.jj 2013-02-28 23:53:11.000000000 +0100
+++ libcpp/files.c 2013-03-01 16:36:09.849026241 +0100
@@ -1776,6 +1776,7 @@ _cpp_save_file_entries (cpp_reader *pfil
struct pchf_data *result;
size_t result_size;
_cpp_file *f;
+ bool ret;
for (f = pfile->all_files; f; f = f->next_file)
++count;
@@ -1832,7 +1833,9 @@ _cpp_save_file_entries (cpp_reader *pfil
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. */
--- libcpp/pch.c.jj 2013-01-15 09:04:55.000000000 +0100
+++ libcpp/pch.c 2013-03-01 17:05:59.048498975 +0100
@@ -187,6 +187,16 @@ cpp_string_eq (const void *a_p, const vo
&& 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
return -1;
}
free (ss->definedstrs);
+ free (ss->defs);
+ htab_delete (ss->definedhash);
/* Free the saved state. */
free (ss);
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix libcpp PCH related memory leaks (PR middle-end/56461)
2013-03-01 20:17 [PATCH] Fix libcpp PCH related memory leaks (PR middle-end/56461) Jakub Jelinek
@ 2013-03-01 21:03 ` Tom Tromey
0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2013-03-01 21:03 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
>>>>> "Jakub" == Jakub Jelinek <jakub@redhat.com> writes:
Jakub> 2013-03-01 Jakub Jelinek <jakub@redhat.com>
Jakub> PR middle-end/56461
Jakub> * files.c (_cpp_save_file_entries): Free result at the end.
Jakub> * pch.c (cpp_string_free): New function.
Jakub> (cpp_save_state): Use it in htab_create call.
Jakub> (cpp_write_pch_deps): Free ss->defs. Destroy ss->definedhash.
Looks good to me. This is ok, thanks.
Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-03-01 21:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-01 20:17 [PATCH] Fix libcpp PCH related memory leaks (PR middle-end/56461) Jakub Jelinek
2013-03-01 21:03 ` Tom Tromey
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).