[PATCH v6 7/9] trace-cmd library: Avoid memory leak when setting trace clock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The API for setting a trace clock to a input handle did not check if the
clock is already set:
 tracecmd_set_out_clock()
This could cause a memory leak, if the clock is alredy set - the old
clock string is overwritten. The old clock should be freed before
setting the new one.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@xxxxxxxxx>
---
 lib/trace-cmd/trace-output.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index cc27c245..4f31f58b 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -211,8 +211,10 @@ void tracecmd_set_quiet(struct tracecmd_output *handle, bool set_quiet)
 
 void tracecmd_set_out_clock(struct tracecmd_output *handle, const char *clock)
 {
-	if (handle && clock)
+	if (handle && clock) {
+		free(handle->trace_clock);
 		handle->trace_clock = strdup(clock);
+	}
 }
 
 /**
-- 
2.33.1




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux