From: Kamalesh Babulal Date: Wed, 29 Jan 2025 09:49:12 +0000 (+0530) Subject: tools-common.c: Fix resource leak in cgroup_string_list_add_directory() X-Git-Tag: v3.2.0~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d0c4cfd7ffe86feeb179a7efc4161401cdc9de82;p=thirdparty%2Flibcgroup.git 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 --- 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++;