summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>2019-01-20 16:59:00 +0100
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>2019-01-21 21:19:13 +0100
commitb6fb1ee51c9a773d2d6044993af6c0fd7499638f (patch)
treee5c0bc712d38cc952f20fc6b095fd0f509084804
parentbe6d4f74c77c6f521afc873d226480e001cb99c2 (diff)
downloadbinutils-gdb-b6fb1ee51c9a773d2d6044993af6c0fd7499638f.tar.gz
Fix leak in event-top.c history expansion
E.g. in gdb.base/default.exp, valgrind detects leaks such as ==17663== 1,438 bytes in 101 blocks are definitely lost in loss record 2,804 of 2,884 ==17663== at 0x4C2BE6D: malloc (vg_replace_malloc.c:309) ==17663== by 0x418A17: xmalloc (common-utils.c:44) ==17663== by 0x4E6F19C: history_expand (histexpand.c:1061) ==17663== by 0x4B4490: handle_line_of_input(buffer*, char const*, int, char const*) (event-top.c:685) ==17663== by 0x4B4562: command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) (event-top.c:753) ... Fix the leak by using an unique_xmalloc_ptr for history_value. gdb/ChangeLog 2019-01-22 Philippe Waroquiers <philippe.waroquiers@skynet.be> * event-top.c (handle_line_of_input): use unique_xmalloc_ptr for history_value.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/event-top.c18
2 files changed, 13 insertions, 10 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 04e8c2d56f3..8e03dbf883f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-01-22 Philippe Waroquiers <philippe.waroquiers@skynet.be>
+
+ * event-top.c (handle_line_of_input): use unique_xmalloc_ptr for
+ history_value.
+
2019-01-21 Tom Tromey <tom@tromey.com>
* ui-out.c: Fix includes.
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 3d3d6275d75..920b47f7e3c 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -679,31 +679,29 @@ handle_line_of_input (struct buffer *cmd_line_buffer,
/* Do history expansion if that is wished. */
if (history_expansion_p && from_tty && input_interactive_p (current_ui))
{
- char *history_value;
+ char *cmd_expansion;
int expanded;
- expanded = history_expand (cmd, &history_value);
+ expanded = history_expand (cmd, &cmd_expansion);
+ gdb::unique_xmalloc_ptr<char> history_value (cmd_expansion);
if (expanded)
{
size_t len;
/* Print the changes. */
- printf_unfiltered ("%s\n", history_value);
+ printf_unfiltered ("%s\n", history_value.get ());
/* If there was an error, call this function again. */
if (expanded < 0)
- {
- xfree (history_value);
- return cmd;
- }
+ return cmd;
/* history_expand returns an allocated string. Just replace
our buffer with it. */
- len = strlen (history_value);
+ len = strlen (history_value.get ());
xfree (buffer_finish (cmd_line_buffer));
- cmd_line_buffer->buffer = history_value;
+ cmd_line_buffer->buffer = history_value.get ();
cmd_line_buffer->buffer_size = len + 1;
- cmd = history_value;
+ cmd = history_value.release ();
}
}