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

Jakub Jelinek jakub@redhat.com
Mon Mar 4 21:11:00 GMT 2013


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

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


More information about the Gcc-patches mailing list