]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgget: fix coverity warning about double free
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 25 May 2022 13:47:48 +0000 (07:47 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 25 May 2022 13:48:03 +0000 (07:48 -0600)
Fix double free warning, reported by Coverity tool:

CID 258297 (#1 of 1): Double free (USE_AFTER_FREE). double_free:
Calling closedir frees pointer dir which has already been freed.

As per the man page, the closedir(), closes the directory stream
associated with the dirp, but is ambiguous about if dirp is set to NULL
or not. Coverity answers that with the above report, that dirp is not
NULL and hence the double free.

Fixes: fea1ab8b45d7 ("tools/cgget: fix coverity warning about resource leak")
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/tools/cgget.c

index 009d468c6f52ee83106e1ec5db6b1654a384d435..b7619cf5de274714062db0d4856edf8fd34c190b 100644 (file)
@@ -625,10 +625,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;