Fix memory leak in exception code
authorTom Tromey <tromey@adacore.com>
Wed, 24 Apr 2019 18:13:35 +0000 (12:13 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 25 Apr 2019 18:59:35 +0000 (12:59 -0600)
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.

gdb/ChangeLog
gdb/event-top.c

index 3e28e77cb73980b16108a11a10f9a944aa5a9dd6..17e10e869b8d542a88727e68c819eb5babb3764b 100644 (file)
@@ -1,3 +1,9 @@
+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
index 9fa46c8ad44bbe2e91ef479c54e97a219269cb8d..3ccf136ff12d3478bd18c81aa3eb043b3f164cee 100644 (file)
@@ -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)
This page took 0.03451 seconds and 4 git commands to generate.