All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools lib traceevent: avoid memory leak: buf
@ 2021-07-01 12:58 gushengxian
  0 siblings, 0 replies; only message in thread
From: gushengxian @ 2021-07-01 12:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: gushengxian

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-01 13:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 12:58 [PATCH] tools lib traceevent: avoid memory leak: buf gushengxian

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.