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]

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


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.

--- 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


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