Skip to content

Commit

Permalink
api.c: fix resource leak in cg_chmod_path()
Browse files Browse the repository at this point in the history
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: d569122 ("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>
  • Loading branch information
kamalesh-babulal authored and drakenclimber committed Oct 25, 2022
1 parent 1b5c842 commit 38f0267
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ int cg_chmod_path(const char *path, mode_t mode, int owner_is_umask)
strerror(errno));
last_errno = errno;

if (fd > 0)
if (fd > -1)
close(fd);

return ECGOTHER;
Expand Down

0 comments on commit 38f0267

Please sign in to comment.