This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch v4 19/24] btrace, linux: fix memory leak when reading branch trace
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Markus Metzger <markus dot t dot metzger at intel dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Sun, 18 Aug 2013 21:08:57 +0200
- Subject: Re: [patch v4 19/24] btrace, linux: fix memory leak when reading branch trace
- References: <1372842874-28951-1-git-send-email-markus dot t dot metzger at intel dot com> <1372842874-28951-20-git-send-email-markus dot t dot metzger at intel dot com>
On Wed, 03 Jul 2013 11:14:29 +0200, Markus Metzger wrote:
> When it takes more than one iteration to read the BTS trace, the trace from the
> previous iteration is leaked. Fix it.
>
> 2013-07-03 Markus Metzger <markus.t.metzger@intel.com>
>
> * common/linux-btrace.c (linux_read_btrace): Free trace from
> previous iteration.
>
>
> ---
> gdb/common/linux-btrace.c | 3 +++
> 1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/gdb/common/linux-btrace.c b/gdb/common/linux-btrace.c
> index 4880f41..b30a6ec 100644
> --- a/gdb/common/linux-btrace.c
> +++ b/gdb/common/linux-btrace.c
> @@ -522,6 +522,9 @@ linux_read_btrace (struct btrace_target_info *tinfo,
> {
> data_head = header->data_head;
>
> + /* Delete any leftover trace from the previous iteration. */
> + VEC_truncate (btrace_block_s, btrace, 0);
This still leaks, you should do VEC_free. Later you do:
*btrace = perf_event_read_bts (tinfo, begin, end, start, size);
which overwrites the whole 'struct *' containing validly setup VEC data just
with zero elements.
> +
> /* If there's new trace, let's read it. */
> if (data_head != tinfo->data_head)
> {
> --
> 1.7.1