From d0c4cfd7ffe86feeb179a7efc4161401cdc9de82 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Wed, 29 Jan 2025 15:19:12 +0530 Subject: [PATCH] tools-common.c: Fix resource leak in cgroup_string_list_add_directory() Fix a Coverity warning about resource leak: CID 465889: (#4 of 4): Resource leak (RESOURCE_LEAK) 32. leaked_storage: Variable fullpath going out of scope leaks the storage it points to. Fix it by releasing the 'fullpath', when file name does not matches '*.conf' code path(s). Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- src/tools/tools-common.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tools/tools-common.c b/src/tools/tools-common.c index d6ed0ce7..f96488fa 100644 --- a/src/tools/tools-common.c +++ b/src/tools/tools-common.c @@ -238,11 +238,15 @@ int cgroup_string_list_add_directory(struct cgroup_string_list *list, char *dirn /* we are interested in .conf files, skip others */ file_ext = strstr(item->d_name, ".conf"); - if (!file_ext) + if (!file_ext) { + free(fullpath); continue; + } - if (strcmp(file_ext, ".conf") || strlen(item->d_name) == 5) + if (strcmp(file_ext, ".conf") || strlen(item->d_name) == 5) { + free(fullpath); continue; + } ret = cgroup_string_list_add_item(list, fullpath); count++; -- 2.47.3