This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix memory leak in diagnostic.c (PR middle-end/56461)
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Dodji Seketeli <dseketel at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Date: Mon, 4 Mar 2013 15:46:25 -0600
- Subject: Re: [PATCH] Fix memory leak in diagnostic.c (PR middle-end/56461)
- References: <20130304211119.GW12913@tucnak.redhat.com>
On Mon, Mar 4, 2013 at 3:11 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> maybe_unwind_expanded_macro_loc now calls diagnostic_append_node
> in two places, but often with non-NULL pp_get_prefix (context->printer).
> diagnostic_append_node overwrites it with a new value, then frees that
> new value and clears it, but that means we leak the old prefix.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
Yes. Thanks!
-- Gaby
>
> 2013-03-04 Jakub Jelinek <jakub@redhat.com>
>
> PR middle-end/56461
> * diagnostic.c (diagnostic_append_note): Save and restore old prefix.
>
> --- gcc/diagnostic.c.jj 2013-01-15 17:20:35.000000000 +0100
> +++ gcc/diagnostic.c 2013-03-04 17:01:35.735413481 +0100
> @@ -828,6 +828,7 @@ diagnostic_append_note (diagnostic_conte
> {
> diagnostic_info diagnostic;
> va_list ap;
> + const char *saved_prefix;
>
> va_start (ap, gmsgid);
> diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_NOTE);
> @@ -836,12 +837,14 @@ diagnostic_append_note (diagnostic_conte
> va_end (ap);
> return;
> }
> + saved_prefix = pp_get_prefix (context->printer);
> pp_set_prefix (context->printer,
> diagnostic_build_prefix (context, &diagnostic));
> pp_newline (context->printer);
> pp_format (context->printer, &diagnostic.message);
> pp_output_formatted_text (context->printer);
> pp_destroy_prefix (context->printer);
> + pp_set_prefix (context->printer, saved_prefix);
> diagnostic_show_locus (context, &diagnostic);
> va_end(ap);
> }
>
> Jakub