[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gdb-cvs
Subject:    [binutils-gdb] Fix memory leak in exception code
From:       Tom Tromey <tromey () sourceware ! org>
Date:       2019-04-25 19:00:45
Message-ID: 20190425190045.58962.qmail () sourceware ! org
[Download RAW message or body]

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

commit 3d1cbb78936fbf2985ffd2ebf074841599ead788
Author: Tom Tromey <tromey@adacore.com>
Date:   Wed Apr 24 12:13:35 2019 -0600

    Fix memory leak in exception code
    
    PR gdb/24475 concerns a memory leak coming from gdb's exception
    handling code.
    
    The leak occurs because throw_exception_sjlj does not arrange to
    destroy the exception object it is passed.  However, because
    gdb_exception has a destructor, it's undefined to longjmp in this
    situation.
    
    This patch fixes the problem by avoiding the need to run any
    destructors in gdb_rl_callback_handler, by making the gdb_exception
    "static".
    
    gdb/ChangeLog
    2019-04-25  Tom Tromey  <tromey@adacore.com>
    
    	PR gdb/24475:
    	* event-top.c (gdb_rl_callback_handler): Make "gdb_rl_expt"
    	static.

Diff:
---
 gdb/ChangeLog   | 6 ++++++
 gdb/event-top.c | 6 +++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3e28e77..17e10e8 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2019-04-25  Tom Tromey  <tromey@adacore.com>
 
+	PR gdb/24475:
+	* event-top.c (gdb_rl_callback_handler): Make "gdb_rl_expt"
+	static.
+
+2019-04-25  Tom Tromey  <tromey@adacore.com>
+
 	* xml-support.c (struct gdb_xml_parser) <set_error>: Take an
 	rvalue reference.
 	(gdb_xml_start_element_wrapper, gdb_xml_end_element_wrapper)
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 9fa46c8..3ccf136 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -205,11 +205,15 @@ gdb_rl_callback_read_char_wrapper (gdb_client_data client_data)
 static void
 gdb_rl_callback_handler (char *rl) noexcept
 {
-  struct gdb_exception gdb_rl_expt;
+  /* This is static to avoid undefined behavior when calling longjmp
+     -- gdb_exception has a destructor with side effects.  */
+  static struct gdb_exception gdb_rl_expt;
   struct ui *ui = current_ui;
 
   try
     {
+      /* Ensure the exception is reset on each call.  */
+      gdb_rl_expt = {};
       ui->input_handler (gdb::unique_xmalloc_ptr<char> (rl));
     }
   catch (gdb_exception &ex)
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic