[PATCH 08/38] trace-cmd lib: prevent a memory leak in create_event_list_item()

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

 



Free ptr if malloc() fails.

Fixes a RESOURCE_LEAK error (CWE-772)

Signed-off-by: Jerome Marchand <jmarchan@xxxxxxxxxx>
---
 lib/trace-cmd/trace-output.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index 59498edc..4a9ecc5d 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -955,7 +955,8 @@ create_event_list_item(struct tracecmd_output *handle,
 	free(str);
 	return;
  err_mem:
-	 tracecmd_warning("Insufficient memory");
+	free(ptr);
+	tracecmd_warning("Insufficient memory");
 }
 
 static int read_ftrace_files(struct tracecmd_output *handle, bool compress)
-- 
2.44.0





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

  Powered by Linux