[CRIU] [PATCH 2/2] mount: fix cwd_fd leak on clone error

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Mon Jan 29 11:21:08 MSK 2018


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 <ptikhomirov at virtuozzo.com>
---
 criu/mount.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/criu/mount.c b/criu/mount.c
index a62c1c6ac..4c7fd0914 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;
 		}
 	}
 
-- 
2.14.3



More information about the CRIU mailing list