diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2015-07-06 18:16:24 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2015-07-10 12:39:03 +0100 |
commit | c101f28fea4fc8621bdf864bc6e2132244dbe6a7 (patch) | |
tree | ea1fd93cd91e517c7afac8138e9b51bd0cf48626 /gdb/tui | |
parent | 150375dc7ac877d1dc6e8aaf73a23479b720306c (diff) | |
download | binutils-c101f28fea4fc8621bdf864bc6e2132244dbe6a7.zip binutils-c101f28fea4fc8621bdf864bc6e2132244dbe6a7.tar.gz binutils-c101f28fea4fc8621bdf864bc6e2132244dbe6a7.tar.bz2 |
gdb/tui: Use cleanups to free string copies.
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.
Diffstat (limited to 'gdb/tui')
-rw-r--r-- | gdb/tui/tui-win.c | 9 |
1 files changed, 6 insertions, 3 deletions
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); } } |