This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix two potential memory leak


> Summary variables should be deleted at the end of write_summary.
> It's first newed in generate_summary, and second newed in read_summary.
> Therefore, delete the first in write_summary, delete the second in
> execute.
> 
> gcc/ChangeLog:
> 
> 	2019-11-26  Luo Xiong Hu  <luoxhu@linux.ibm.com>
> 
> 	* ipa-pure-const.c (pure_const_write_summary): Fix memory leak.
> 	* ipa-sra.c (ipa_sra_write_summary): Likewise.

This is not going to work with -ffat-lto-objects because in this case
IPA pass is executed later.  So you will need
if (!flag_fat_lto_objects).

I think most IPA passes just waits for compiler to exit with LTO rather
than free the summary.  ipa-fnsummary and ipa-prop allocate optimization
summaries, too. Are those freed?

Honza
> ---
>  gcc/ipa-pure-const.c | 3 +++
>  gcc/ipa-sra.c        | 5 +++++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
> index a142e0cc8f6..89f334cedac 100644
> --- a/gcc/ipa-pure-const.c
> +++ b/gcc/ipa-pure-const.c
> @@ -1260,6 +1260,9 @@ pure_const_write_summary (void)
>      }
>  
>    lto_destroy_simple_output_block (ob);
> +
> +  delete funct_state_summaries;
> +  funct_state_summaries = NULL;
>  }
>  
>  
> diff --git a/gcc/ipa-sra.c b/gcc/ipa-sra.c
> index c6ed0f44b87..bbc5e84edfb 100644
> --- a/gcc/ipa-sra.c
> +++ b/gcc/ipa-sra.c
> @@ -2671,6 +2671,11 @@ ipa_sra_write_summary (void)
>    streamer_write_char_stream (ob->main_stream, 0);
>    produce_asm (ob, NULL);
>    destroy_output_block (ob);
> +
> +  ggc_delete (func_sums);
> +  func_sums = NULL;
> +  delete call_sums;
> +  call_sums = NULL;
>  }
>  
>  /* Read intraprocedural analysis information about E and all of its outgoing
> -- 
> 2.21.0.777.g83232e3864
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]