From: Kamalesh Babulal Date: Tue, 25 Oct 2022 21:26:02 +0000 (-0600) Subject: api.c: fix resource leak in cg_chmod_path() X-Git-Tag: v3.1.0~280 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2e192adfb6c6824163b4db8da07efe6d01f617b;p=thirdparty%2Flibcgroup.git api.c: fix resource leak in cg_chmod_path() 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: 91cf2e4b7ceb ("api.c: fix file open in cg_chmod_path()") Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/api.c b/src/api.c index 92e211dd..d8163e67 100644 --- a/src/api.c +++ b/src/api.c @@ -248,7 +248,7 @@ fail: cgroup_warn("cannot change permissions of file %s: %s\n", path, strerror(errno)); last_errno = errno; - if (fd > 0) + if (fd > -1) close(fd); return ECGOTHER;