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