[CRIU] [PATCH 4/8] criu: don't call close() for a negative value

Andrei Vagin avagin at openvz.org
Fri Feb 16 10:21:16 MSK 2018


[This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing]

From: Andrei Vagin <avagin at virtuozzo.com>

CID 73358 (#1 of 1): Improper use of negative value (NEGATIVE_RETURNS)
8. negative_returns: sk is passed to a parameter that cannot be negative. [hide details]

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/kerndat.c    | 4 ++--
 criu/sk-netlink.c | 2 +-
 criu/util.c       | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/criu/kerndat.c b/criu/kerndat.c
index 0aab25528..cf76862d9 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -495,7 +495,7 @@ int kerndat_fdinfo_has_lock()

        exit_code = 0;
 out:
-       close(pfd);
+       close_safe(&pfd);
        close(fd);

        return exit_code;
@@ -770,7 +770,7 @@ int kerndat_has_ns_get_parent(void)
        p_ns = ioctl(ns, NS_GET_PARENT);
        if (p_ns >= 0 || errno == EPERM) {
                kdat.has_ns_get_parent = true;
-               close(p_ns);
+               close_safe(&p_ns);
        }

        close(ns);
diff --git a/criu/sk-netlink.c b/criu/sk-netlink.c
index 2761305d1..b522963e8 100644
--- a/criu/sk-netlink.c
+++ b/criu/sk-netlink.c
@@ -245,7 +245,7 @@ static int open_netlink_sk(struct file_desc *d, int *new_fd)
        *new_fd = sk;
        return 0;
 err:
-       close(sk);
+       close_safe(&sk);
        return -1;
 }

diff --git a/criu/util.c b/criu/util.c
index c9d98387d..b19bf5175 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -1368,7 +1368,7 @@ int run_tcp_server(bool daemon_mode, int *ask, int cfd, int sk)

        return 0;
 out:
-       close(sk);
+       close_safe(&sk);
        return -1;
 }

--
2.13.6




More information about the CRIU mailing list