From 9966699d7a9d8e35c0c4cf9a945bcf90ef874f2d Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Sun, 14 Feb 2021 23:24:44 +0100 Subject: [PATCH] Fix memory leak in ipa-refernece 2021-02-14 Jan Hubicka Richard Biener PR ipa/97346 * ipa-reference.c (ipa_init): Only conditinally initialize reference_vars_to_consider. (propagate): Conditionally deninitialize reference_vars_to_consider. (ipa_reference_write_optimization_summary): Sanity check that reference_vars_to_consider is not allocated. --- gcc/ipa-reference.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/gcc/ipa-reference.c b/gcc/ipa-reference.c index 2ea2a6d5327..6cf78ff94a6 100644 --- a/gcc/ipa-reference.c +++ b/gcc/ipa-reference.c @@ -458,8 +458,8 @@ ipa_init (void) ipa_init_p = true; - vec_alloc (reference_vars_to_consider, 10); - + if (dump_file) + vec_alloc (reference_vars_to_consider, 10); if (ipa_ref_opt_sum_summaries != NULL) { @@ -967,8 +967,12 @@ propagate (void) } if (dump_file) - vec_free (reference_vars_to_consider); - reference_vars_to_consider = NULL; + { + vec_free (reference_vars_to_consider); + reference_vars_to_consider = NULL; + } + else + gcc_checking_assert (!reference_vars_to_consider); return remove_p ? TODO_remove_functions : 0; } @@ -1059,6 +1063,7 @@ ipa_reference_write_optimization_summary (void) auto_bitmap ltrans_statics; int i; + gcc_checking_assert (!reference_vars_to_consider); vec_alloc (reference_vars_to_consider, ipa_reference_vars_uids); reference_vars_to_consider->safe_grow (ipa_reference_vars_uids, true); @@ -1117,7 +1122,8 @@ ipa_reference_write_optimization_summary (void) } } lto_destroy_simple_output_block (ob); - delete reference_vars_to_consider; + vec_free (reference_vars_to_consider); + reference_vars_to_consider = NULL; } /* Deserialize the ipa info for lto. */ -- 2.30.2