[PATCH] tools lib traceevent: avoid memory leak: buf
From: gushengxian
Date: Thu Jul 01 2021 - 09:01:23 EST
From: gushengxian <gushengxian@xxxxxxxxxx>
buf is realloced so free(buf) should be added to avoid memory leak.
Signed-off-by: gushengxian <gushengxian@xxxxxxxxxx>
---
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