public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 5/5] Fix memory leak in exception code
Date: Thu, 25 Apr 2019 16:58:00 -0000	[thread overview]
Message-ID: <20190425165256.31226-6-tromey@adacore.com> (raw)
In-Reply-To: <20190425165256.31226-1-tromey@adacore.com>

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   | 6 ++++++
 gdb/event-top.c | 6 +++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gdb/event-top.c b/gdb/event-top.c
index 9fa46c8ad44..f4a7574741a 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.  */
+  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)
-- 
2.20.1

  parent reply	other threads:[~2019-04-25 16:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-25 16:53 [PATCH 0/5] More exception-handling improvements Tom Tromey
2019-04-25 16:53 ` [PATCH 3/5] Avoid undefined behavior in Guile exception handling Tom Tromey
2019-04-25 16:53 ` [PATCH 2/5] Make SJLJ exceptions more efficient Tom Tromey
2019-04-25 16:53 ` [PATCH 1/5] Remove exception_none Tom Tromey
2019-04-25 16:58 ` [PATCH 4/5] Make exception handling more efficient Tom Tromey
2019-04-25 16:58 ` Tom Tromey [this message]
2019-04-25 18:06   ` [PATCH 5/5] Fix memory leak in exception code Pedro Alves
2019-04-25 18:18     ` Tom Tromey
2019-04-25 18:30       ` Tom Tromey
2019-04-25 18:38         ` Pedro Alves
2019-04-25 18:50           ` Tom Tromey
2019-04-25 18:08 ` [PATCH 0/5] More exception-handling improvements Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190425165256.31226-6-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).