This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] Fix leak in record-full.c
- From: Philippe Waroquiers <philippe at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 1 Jan 2019 19:29:14 -0000
- Subject: [binutils-gdb] Fix leak in record-full.c
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ec70d8db32462176e7da60d28b0c1978fc6b70d3
commit ec70d8db32462176e7da60d28b0c1978fc6b70d3
Author: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Date: Tue Jan 1 14:12:30 2019 +0100
Fix leak in record-full.c
valgrind detects leaks in several gdb.reverse tests,
such as the below in gdb.reverse/watch-precsave.exp.
Fix the leak by rewriting the loop that frees
record_full_core_buf_list.
gdb/ChangeLog
2019-01-01 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* record-full.c (record_full_base_target::close): Rewrite
record_full_core_buf_list free logic.
==18847== VALGRIND_GDB_ERROR_BEGIN
==18847== 4,120 (24 direct, 4,096 indirect) bytes in 1 blocks are definitely lost in loss record 3,094 of 3,199
==18847== at 0x4C2BE6D: malloc (vg_replace_malloc.c:309)
==18847== by 0x405097: xmalloc (common-utils.c:44)
==18847== by 0x5AF8EA: xnew<record_full_core_buf_entry> (poison.h:110)
==18847== by 0x5AF8EA: record_full_core_target::xfer_partial(target_object, char const*, unsigned char*, unsigned char const*, unsigned long, unsigned long, unsigned long*) (record-full.c:2182)
==18847== by 0x64677D: raw_memory_xfer_partial(target_ops*, unsigned char*, unsigned char const*, unsigned long, long, unsigned long*) (target.c:956)
==18847== by 0x64691E: memory_xfer_partial_1(target_ops*, target_object, unsigned char*, unsigned char const*, unsigned long, unsigned long, unsigned long*) (target.c:1086)
Diff:
---
gdb/ChangeLog | 5 +++++
gdb/record-full.c | 12 ++++--------
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2402d73..a2d3601 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2019-01-01 Philippe Waroquiers <philippe.waroquiers@skynet.be>
+ * record-full.c (record_full_base_target::close): Rewrite
+ record_full_core_buf_list free logic.
+
+2019-01-01 Philippe Waroquiers <philippe.waroquiers@skynet.be>
+
* break-catch-syscall.c (print_one_catch_syscall): xfree
the last text.
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 2b918ea..8738512 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -1014,15 +1014,11 @@ record_full_base_target::close ()
}
/* Release record_full_core_buf_list. */
- if (record_full_core_buf_list)
+ while (record_full_core_buf_list)
{
- for (entry = record_full_core_buf_list->prev; entry;
- entry = entry->prev)
- {
- xfree (record_full_core_buf_list);
- record_full_core_buf_list = entry;
- }
- record_full_core_buf_list = NULL;
+ entry = record_full_core_buf_list;
+ record_full_core_buf_list = record_full_core_buf_list->prev;
+ xfree (entry);
}
if (record_full_async_inferior_event_token)