This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB 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] Plug memory leak in infcmd.c:print_return_value()


Discovered by inspection.  The fact that the variables `stb' was
declared static suggests that someone intended to re-use it.  However,
the ui_out stream object was create afresh with each call.  This patch
makes sure we properly delete the object.  I removed some duplicate
code in the process.

I also sneaked in an s/structure_return/struct_return/.  This is more
consistent with other bits in code that have a variable with the same
meaning.

Committed as obvous,

Mark


Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>
 
	* infcmd.c (print_return_value): Plug memory leak; delete
	ui_stream object.  Rename argument `structure_return' to
	`struct_return'.

Index: infcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/infcmd.c,v
retrieving revision 1.102
diff -u -p -r1.102 infcmd.c
--- infcmd.c 25 Jan 2004 17:32:45 -0000 1.102
+++ infcmd.c 25 Jan 2004 20:55:23 -0000
@@ -1050,22 +1050,16 @@ advance_command (char *arg, int from_tty
 /* Print the result of a function at the end of a 'finish' command.  */
 
 static void
-print_return_value (int structure_return, struct type *value_type)
+print_return_value (int struct_return, struct type *value_type)
 {
+  struct cleanup *old_chain;
+  struct ui_stream *stb;
   struct value *value;
-  static struct ui_stream *stb = NULL;
 
-  if (!structure_return)
+  if (!struct_return)
     {
+      /* The return value can be found in the inferior's registers.  */
       value = register_value_being_returned (value_type, stop_registers);
-      stb = ui_out_stream_new (uiout);
-      ui_out_text (uiout, "Value returned is ");
-      ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
-			record_latest_value (value));
-      ui_out_text (uiout, " = ");
-      value_print (value, stb->stream, 0, Val_no_prettyprint);
-      ui_out_field_stream (uiout, "return-value", stb);
-      ui_out_text (uiout, "\n");
     }
   /* FIXME: 2003-09-27: When returning from a nested inferior function
      call, it's possible (with no help from the architecture vector)
@@ -1110,15 +1104,19 @@ print_return_value (int structure_return
 	  EXTRACT_RETURN_VALUE (value_type, stop_registers,
 				VALUE_CONTENTS_RAW (value));
 	}
-      stb = ui_out_stream_new (uiout);
-      ui_out_text (uiout, "Value returned is ");
-      ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
-			record_latest_value (value));
-      ui_out_text (uiout, " = ");
-      value_print (value, stb->stream, 0, Val_no_prettyprint);
-      ui_out_field_stream (uiout, "return-value", stb);
-      ui_out_text (uiout, "\n");
     }
+
+  /* Print it.  */
+  stb = ui_out_stream_new (uiout);
+  old_chain = make_cleanup_ui_out_stream_delete (stb);
+  ui_out_text (uiout, "Value returned is ");
+  ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
+		    record_latest_value (value));
+  ui_out_text (uiout, " = ");
+  value_print (value, stb->stream, 0, Val_no_prettyprint);
+  ui_out_field_stream (uiout, "return-value", stb);
+  ui_out_text (uiout, "\n");
+  do_cleanups (old_chain);
 }
 
 /* Stuff that needs to be done by the finish command after the target


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