]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools-common.c: Fix resource leak in cgroup_string_list_add_directory()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 29 Jan 2025 09:49:12 +0000 (15:19 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 31 Jan 2025 20:59:57 +0000 (13:59 -0700)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/tools/tools-common.c

index d6ed0ce7f255a21a04716e670ca14007f1a3bdcb..f96488fa193d1b99a87eda1884556de9cbf20d5f 100644 (file)
@@ -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++;