This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix two potential memory leak
- From: Jan Hubicka <hubicka at ucw dot cz>
- To: luoxhu <luoxhu at linux dot ibm dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Martin Jambor <mjambor at suse dot cz>, Segher Boessenkool <segher at kernel dot crashing dot org>, Bill Schmidt <wschmidt at linux dot ibm dot com>
- Date: Tue, 26 Nov 2019 09:04:18 +0100
- Subject: Re: [PATCH] Fix two potential memory leak
- References: <89d1b4b1-eda4-f8f2-a8c6-0d86fce853d1@linux.ibm.com>
> 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
>