]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: fix resource leak in cg_chmod_path()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 25 Oct 2022 21:28:51 +0000 (15:28 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 25 Oct 2022 21:29:54 +0000 (15:29 -0600)
Fix resource leak, reported by Coverity Tool:

CID 276160 (#1 of 1): Resource leak (RESOURCE_LEAK)10. leaked_handle:
Handle variable fd going out of scope leaks the handle.

In cg_chmod_path(), the file descriptor checks for fd > 0, Coverity
warns about the possibility of the file descriptor being 0, fix it by
changing the check from '0' -> '-1'.

Fixes: d569122a8c5f ("api.c: fix file open in cg_chmod_path()")
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 8b7c665f356aa2845da9709379d0b027772363c2..2c30ad3215efe230c3b5972d401a3d84823cbda7 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -240,7 +240,7 @@ fail:
                        strerror(errno));
        last_errno = errno;
 
-       if (fd > 0)
+       if (fd > -1)
                close(fd);
 
        return ECGOTHER;