From f48bf9825fcdc169f20d3ec6ef7d509d87c8bc46 Mon Sep 17 00:00:00 2001 From: Pavel Tikhomirov Date: Mon, 29 Jan 2018 11:21:08 +0300 Subject: [PATCH] mount: fix cwd_fd leak on clone error We should close cwd_fd on error paths, found by Coverity Scan: *** CID 187162: Resource leaks (RESOURCE_LEAK) /criu/mount.c: 1370 in open_mountpoint() 1364 */ 1365 pid = clone_noasan(ns_open_mountpoint, CLONE_VFORK | CLONE_VM 1366 | CLONE_FILES | CLONE_IO | CLONE_SIGHAND 1367 | CLONE_SYSVSEM, &ca); 1368 if (pid == -1) { 1369 pr_perror("Can't clone helper process"); >>> CID 187162: Resource leaks (RESOURCE_LEAK) >>> Handle variable "cwd_fd" going out of scope leaks the handle. 1370 return -1; 1371 } 1372 1373 errno = 0; 1374 if (waitpid(pid, &status, __WALL) != pid || !WIFEXITED(status) 1375 || WEXITSTATUS(status)) { Signed-off-by: Pavel Tikhomirov Signed-off-by: Andrei Vagin --- criu/mount.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/criu/mount.c b/criu/mount.c index 89a3ac90d..1beff348f 100644 --- a/criu/mount.c +++ b/criu/mount.c @@ -1367,7 +1367,7 @@ int open_mountpoint(struct mount_info *pm) | CLONE_SYSVSEM, &ca); if (pid == -1) { pr_perror("Can't clone helper process"); - return -1; + goto err; } errno = 0; @@ -1375,7 +1375,7 @@ int open_mountpoint(struct mount_info *pm) || WEXITSTATUS(status)) { pr_err("Can't wait or bad status: errno=%d, status=%d\n", errno, status); - return -1; + goto err; } }