[CRIU] [PATCH 05/18] kerndat: don't call close for a negative value

Andrei Vagin avagin at openvz.org
Thu Nov 9 22:20:59 MSK 2017


From: Andrei Vagin <avagin at virtuozzo.com>

CID 92720 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
11. negative_returns: pfd is passed to a parameter that cannot be negative.

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

CID 181218 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
6. negative_returns: p_ns is passed to a parameter that cannot be negative.

CID 179043 (#1-2 of 2): Use after close (USE_AFTER_FREE)
6. pass_closed_arg: Passing closed handle f.fd as an argument to bclose.

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

diff --git a/criu/bfd.c b/criu/bfd.c
index 8269ab1a2..ced80c942 100644
--- a/criu/bfd.c
+++ b/criu/bfd.c
@@ -91,7 +91,7 @@ static void buf_put(struct xbuf *xb)
 static int bfdopen(struct bfd *f, bool writable)
 {
 	if (buf_get(&f->b)) {
-		close(f->fd);
+		close_safe(&f->fd);
 		return -1;
 	}
 
diff --git a/criu/kerndat.c b/criu/kerndat.c
index b71df1c7c..8c8976801 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -495,8 +495,8 @@ int kerndat_fdinfo_has_lock()
 
 	exit_code = 0;
 out:
-	close(pfd);
-	close(fd);
+	close_safe(&pfd);
+	close_safe(&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/util.c b/criu/util.c
index 28fc80488..5ba49510a 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -1291,7 +1291,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