]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgxget: fix coverity warning about resource leak
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 25 May 2022 17:11:43 +0000 (11:11 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 25 May 2022 17:11:48 +0000 (11:11 -0600)
Fix a resource leaks reported by Coverity tool:

CID 258302 (#1 of 1): Resource leak (RESOURCE_LEAK). leaked_storage:
Variable dir going out of scope leaks the storage it points to

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/tools/cgxget.c

index 5157f8f596ac2312ef44ca582a023e7f42d879a1..9cc75d3247e16b48baa20da9d17f00be62bc1b2e 100644 (file)
@@ -654,10 +654,8 @@ static int fill_empty_controller(struct cgroup * const cg,
                        continue;
 
                ret = cgroup_fill_cgc(ctrl_dir, cg, cgc, i);
-               if (ret == ECGFAIL) {
-                       closedir(dir);
+               if (ret == ECGFAIL)
                        goto out;
-               }
 
                if (cgc->index > 0) {
                        cgc->values[cgc->index - 1]->dirty = false;
@@ -675,9 +673,10 @@ static int fill_empty_controller(struct cgroup * const cg,
                }
        }
 
-       closedir(dir);
-
 out:
+       if (dir)
+               closedir(dir);
+
        pthread_rwlock_unlock(&cg_mount_table_lock);
 
        return ret;