Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCH 4/4] gdb: Add cleanup to avoid memory leak on error.
Date: Wed, 20 May 2015 23:18:00 -0000	[thread overview]
Message-ID: <deb6b2ee05573ce1309174d61f7f37650b108f45.1432163460.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1432163460.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1432163460.git.andrew.burgess@embecosm.com>

Use cleanup to avoid leaking memory if an error occurs during tui
start up.

gdb/ChangeLog:

	* tui/tui-layout.c (tui_set_layout_for_display_command): Ensure
	buf_ptr is freed.
---
 gdb/ChangeLog        | 5 +++++
 gdb/tui/tui-layout.c | 4 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8ea1a5e..78e5654 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2015-05-20  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* tui/tui-layout.c (tui_set_layout_for_display_command): Ensure
+	buf_ptr is freed.
+
+2015-05-20  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* tui/tui-layout.c (tui_layout_command): Move call to tui_enable
 	into ...
 	(tui_set_layout_for_display_command): ...here, before calling
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 2e950f7..0614b2c 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -426,10 +426,12 @@ tui_set_layout_for_display_command (const char *layout_name)
       char *buf_ptr;
       enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
       enum tui_layout_type cur_layout = tui_current_layout ();
+      struct cleanup *old_chain;
 
       buf_ptr = (char *) xstrdup (layout_name);
       for (i = 0; (i < strlen (layout_name)); i++)
 	buf_ptr[i] = toupper (buf_ptr[i]);
+      old_chain = make_cleanup (xfree, buf_ptr);
 
       /* First check for ambiguous input.  */
       if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S')
@@ -467,7 +469,7 @@ tui_set_layout_for_display_command (const char *layout_name)
 	      tui_set_layout (new_layout);
 	    }
 	}
-      xfree (buf_ptr);
+      do_cleanups (old_chain);
     }
   else
     status = TUI_FAILURE;
-- 
2.4.0


  parent reply	other threads:[~2015-05-20 23:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-20 23:17 [PATCH 0/4] layout command changes Andrew Burgess
2015-05-20 23:18 ` [PATCH 3/4] gdb: Don't call tui_enable too early Andrew Burgess
2015-05-20 23:18 ` [PATCH 1/4] gdb: Remove register class specific layout names Andrew Burgess
2015-05-21  8:42   ` Pedro Alves
2015-05-21 11:33     ` Andrew Burgess
2015-05-21 11:34       ` Pedro Alves
2015-05-21 12:25   ` Andrew Burgess
2015-05-21 13:17     ` Pedro Alves
2015-05-20 23:18 ` [PATCH 2/4] gdb: Add completer for layout command Andrew Burgess
2015-05-21  0:25   ` Keith Seitz
2015-05-21  7:10     ` Andrew Burgess
2015-05-20 23:18 ` Andrew Burgess [this message]
2015-05-21  8:12 ` [PATCH 0/4] layout command changes Pedro Alves
2015-05-21  8:35   ` 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=deb6b2ee05573ce1309174d61f7f37650b108f45.1432163460.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.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