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 3/3] gdb/tui: Use cleanups to free string copies.
Date: Wed, 08 Jul 2015 20:37:00 -0000	[thread overview]
Message-ID: <2bc5aca25e4fbde8ac236496c715c67bf8eec3c0.1436387456.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1436387456.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1436387456.git.andrew.burgess@embecosm.com>

In parse_scrolling_args it is possible for a string copy to leak if an
error occurs.  Switching to using a cleanup fixes this leak.

In tui_set_win_height the string can't be leaked, but switching to using
a cleanup guards against the possibility that a leak could be introduced
in the future (by adding an error somewhere in the call stack).

gdb/ChangeLog:

	* tui/tui-win.c (tui_set_win_height): Use a cleanup to free the
	string copy.
	(parse_scrolling_args): Likewise.
---
 gdb/ChangeLog     | 6 ++++++
 gdb/tui/tui-win.c | 9 ++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 646bc5b..e995f01 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2015-07-06  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* tui/tui-win.c (tui_set_win_height): Use a cleanup to free the
+	string copy.
+	(parse_scrolling_args): Likewise.
+
+2015-07-06  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* tui/tui-win.c (focus_completer): Don't duplicate the tui window
 	names in this function.
 
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 947608a..cdf322b 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -1141,7 +1141,9 @@ tui_set_win_height (char *arg, int from_tty)
       char *wname = (char *) NULL;
       int new_height, i;
       struct tui_win_info *win_info;
+      struct cleanup *old_chain;
 
+      old_chain = make_cleanup (xfree, buf);
       wname = buf_ptr;
       buf_ptr = strchr (buf_ptr, ' ');
       if (buf_ptr != (char *) NULL)
@@ -1204,8 +1206,7 @@ The window name specified must be valid and visible.\n"));
       else
 	printf_filtered (WIN_HEIGHT_USAGE);
 
-      if (buf != (char *) NULL)
-	xfree (buf);
+      do_cleanups (old_chain);
     }
   else
     printf_filtered (WIN_HEIGHT_USAGE);
@@ -1636,9 +1637,11 @@ parse_scrolling_args (char *arg,
   if (arg != (char *) NULL)
     {
       char *buf, *buf_ptr;
+      struct cleanup *old_chain;
 
       /* Process the number of lines to scroll.  */
       buf = buf_ptr = xstrdup (arg);
+      old_chain = make_cleanup (xfree, buf);
       if (isdigit (*buf_ptr))
 	{
 	  char *num_str;
@@ -1686,6 +1689,6 @@ The window name specified must be valid and visible.\n"));
 	  else if (*win_to_scroll == TUI_CMD_WIN)
 	    *win_to_scroll = (tui_source_windows ())->list[0];
 	}
-      xfree (buf);
+      do_cleanups (old_chain);
     }
 }
-- 
2.4.0


  reply	other threads:[~2015-07-08 20:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 20:37 [PATCH 0/3] convert tui window names to lower case Andrew Burgess
2015-07-08 20:37 ` Andrew Burgess [this message]
2015-07-08 20:37 ` [PATCH 1/3] gdb: Convert TUI windows " Andrew Burgess
2015-07-08 20:37 ` [PATCH 2/3] gdb/tui: Define tui window names once Andrew Burgess
2015-07-08 20:52 ` [PATCH 0/3] convert tui window names to lower case Patrick Palka
2015-07-09 10:44   ` Pedro Alves
2015-07-09 12:53   ` Patrick Palka

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=2bc5aca25e4fbde8ac236496c715c67bf8eec3c0.1436387456.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