Commit aa1d24a7 authored by Pavel Emelyanov's avatar Pavel Emelyanov

util: Do not leak dup-ed file descriptor

When going daemon criu services ask cr_daemon() to keep
some descriptors open and the routine dup2-s them. The
problem is that the original descriptor is left where it
was and is leaked.

travis-ci: success for util: Do not leak dup-ed file descriptor
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 879d6d1e
......@@ -713,8 +713,15 @@ int cr_daemon(int nochdir, int noclose, int *keep_fd, int close_fd)
if (close_fd != -1)
close(close_fd);
if (*keep_fd != -1)
*keep_fd = dup2(*keep_fd, 3);
if ((*keep_fd != -1) && (*keep_fd != 3)) {
fd = dup2(*keep_fd, 3);
if (fd < 0) {
pr_perror("Dup2 failed");
return -1;
}
close(*keep_fd);
*keep_fd = fd;
}
fd = open("/dev/null", O_RDWR);
if (fd < 0) {
......
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