This is the mail archive of the gdb-cvs@sourceware.org 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]

[binutils-gdb] Memory leak reading frame register during inferior event handling


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0b6e5e108599217c106f5fb63cd8ad7ec7028c5c

commit 0b6e5e108599217c106f5fb63cd8ad7ec7028c5c
Author: Joel Brobecker <brobecker@adacore.com>
Date:   Fri Feb 13 11:57:29 2015 +0100

    Memory leak reading frame register during inferior event handling
    
    When using a conditional breakpoint where the condition evaluated
    to false a large number of times before the program stopped,
    a user reported that GDB's memory consumption was growing very
    quickly until it ran out of memory.
    
    The problem was tracked down to temporary struct values being created
    each time the program stops and handles an inferior event.  Because
    the breakpoint condition usually evaluates to false, there can be
    a fairly large number of such events to be handled before we eventually
    return the prompt to the user (which is when we would normally purge
    such values).
    
    This patch fixes the issue by making sure that handle_inferior_event
    releases all new values created during its execution.
    
    gdb/ChangeLog:
    
            * infrun.c (handle_inferior_event_1): Renames handle_inferior_event.
            (handle_inferior_event): New function.

Diff:
---
 gdb/ChangeLog |  5 +++++
 gdb/infrun.c  | 18 +++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2917022..28d6b71 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2015-05-20  Joel Brobecker  <brobecker@adacore.com>
 
+	* infrun.c (handle_inferior_event_1): Renames handle_inferior_event.
+	(handle_inferior_event): New function.
+
+2015-05-20  Joel Brobecker  <brobecker@adacore.com>
+
 	* ada-lang.c (to_fixed_array_type): Rename local variable
 	typename into type_name.
 
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 71cf208..2f6bc41 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -3680,7 +3680,7 @@ get_inferior_stop_soon (ptid_t ptid)
    once).  */
 
 static void
-handle_inferior_event (struct execution_control_state *ecs)
+handle_inferior_event_1 (struct execution_control_state *ecs)
 {
   enum stop_kind stop_soon;
 
@@ -4202,6 +4202,22 @@ Cannot fill $_exitsignal with the correct signal number.\n"));
     }
 }
 
+/* A wrapper around handle_inferior_event_1, which also makes sure
+   that all temporary struct value objects that were created during
+   the handling of the event get deleted at the end.  */
+
+static void
+handle_inferior_event (struct execution_control_state *ecs)
+{
+  struct value *mark = value_mark ();
+
+  handle_inferior_event_1 (ecs);
+  /* Purge all temporary values created during the event handling,
+     as it could be a long time before we return to the command level
+     where such values would otherwise be purged.  */
+  value_free_to_mark (mark);
+}
+
 /* Come here when the program has stopped with a signal.  */
 
 static void


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