diff mbox

Fix memory leak in diagnostic.c (PR middle-end/56461)

Message ID 20130304211119.GW12913@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek March 4, 2013, 9:11 p.m. UTC
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?

2013-03-04  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/56461
	* diagnostic.c (diagnostic_append_note): Save and restore old prefix.


	Jakub

Comments

Gabriel Dos Reis March 4, 2013, 9:46 p.m. UTC | #1
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
diff mbox

Patch

--- 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);
 }