lkml.org 
[lkml]   [2021]   [Jul]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] tools lib traceevent: avoid memory leak: buf
Date
From: gushengxian <gushengxian@yulong.com>

buf is realloced so free(buf) should be added to avoid memory leak.

Signed-off-by: gushengxian <gushengxian@yulong.com>
---
tools/lib/traceevent/trace-seq.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/lib/traceevent/trace-seq.c b/tools/lib/traceevent/trace-seq.c
index 8d5ecd2bf877..deafb773087e 100644
--- a/tools/lib/traceevent/trace-seq.c
+++ b/tools/lib/traceevent/trace-seq.c
@@ -87,11 +87,13 @@ static void expand_buffer(struct trace_seq *s)
buf = realloc(s->buffer, s->buffer_size + TRACE_SEQ_BUF_SIZE);
if (WARN_ONCE(!buf, "Can't allocate trace_seq buffer memory")) {
s->state = TRACE_SEQ__MEM_ALLOC_FAILED;
+ free(buf);
return;
}

s->buffer = buf;
s->buffer_size += TRACE_SEQ_BUF_SIZE;
+ free(buf);
}

/**
--
2.25.1
\
 
 \ /
  Last update: 2021-07-01 15:01    [W:0.021 / U:0.280 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site