[PATCH 05/15] libtracefs: prevent memory leak in tracefs_event_systems()

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

 



If an error is encountered in the loop, enable and sys might not get
freed. Move the calls to free() before possibly exiting the loop.

Fixes a RESSOURCE_LEAK error (CWE-772)

Signed-off-by: Jerome Marchand <jmarchan@xxxxxxxxxx>
---
 src/tracefs-events.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/tracefs-events.c b/src/tracefs-events.c
index 1b1693c..906dbe8 100644
--- a/src/tracefs-events.c
+++ b/src/tracefs-events.c
@@ -854,12 +854,12 @@ char **tracefs_event_systems(const char *tracing_dir)
 		enable = trace_append_file(sys, "enable");
 
 		ret = stat(enable, &st);
+		free(enable);
+		free(sys);
 		if (ret >= 0) {
 			if (add_list_string(&systems, name) < 0)
 				goto out_free;
 		}
-		free(enable);
-		free(sys);
 	}
 
 	closedir(dir);
-- 
2.44.0





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

  Powered by Linux