[PATCH 13/38] trace-cmd record: prevent a memory leak in show_error()

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

 



In show_error() the pointer p is used for several functions. At some
point it is used to contain the error log file. It's not freed before
being replaced by the result of read_file(path), which is not freed
either. Free p in both case.

Fixes a RESOURCE_LEAK error (CWE-772)

Signed-off-by: Jerome Marchand <jmarchan@xxxxxxxxxx>
---
 tracecmd/trace-record.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index f05a58d1..3e29f922 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -2364,13 +2364,16 @@ static void show_error(const char *file, const char *type)
 			goto read_file;
 		}
 		read_error_log(p);
+		free(p);
 		goto out;
 	}
 
  read_file:
 	p = read_file(path);
-	if (p)
+	if (p) {
 		printf("%s", p);
+		free(p);
+	}
 
  out:
 	printf("Failed %s of %s\n", type, file);
-- 
2.44.0





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

  Powered by Linux