Commit f48bf982 authored by Pavel Tikhomirov's avatar Pavel Tikhomirov Committed by Andrei Vagin

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: 's avatarPavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 455b96c0
...@@ -1367,7 +1367,7 @@ int open_mountpoint(struct mount_info *pm) ...@@ -1367,7 +1367,7 @@ int open_mountpoint(struct mount_info *pm)
| CLONE_SYSVSEM, &ca); | CLONE_SYSVSEM, &ca);
if (pid == -1) { if (pid == -1) {
pr_perror("Can't clone helper process"); pr_perror("Can't clone helper process");
return -1; goto err;
} }
errno = 0; errno = 0;
...@@ -1375,7 +1375,7 @@ int open_mountpoint(struct mount_info *pm) ...@@ -1375,7 +1375,7 @@ int open_mountpoint(struct mount_info *pm)
|| WEXITSTATUS(status)) { || WEXITSTATUS(status)) {
pr_err("Can't wait or bad status: errno=%d, status=%d\n", pr_err("Can't wait or bad status: errno=%d, status=%d\n",
errno, status); errno, status);
return -1; goto err;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment