commit:     219ba2dd9f748c6065c6485020f7de56623e1bc9
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 12 18:15:40 2022 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Feb 12 18:15:40 2022 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=219ba2dd

qmerge: fix Coverity file descriptor leak CID 207952

Leak would happen when opening file succeed, but statting it would fail.
Unlikely, but better to take into account anyway.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 qmerge.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/qmerge.c b/qmerge.c
index a64447e..80affdb 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -1693,8 +1693,9 @@ unlink_empty(const char *buf)
        if (fd != -1 && stat(buf, &st) != -1) {
                if (st.st_size == 0)
                        ret = unlink(buf);
-               close(fd);
        }
+       if (fd != -1)
+               close(fd);
        return ret;
 }
 

Reply via email to