Commit 63b459a2 authored by Andrei Vagin's avatar Andrei Vagin Committed by Pavel Emelyanov

unix: don't leak a file descriptor

1359            if (prep_unix_sk_cwd(ui, &cwd_fd, &root_fd))
>>> >>>     CID 175319:  Resource leaks  (RESOURCE_LEAK)
>>> >>>     Handle variable cwd_fd going out of scope leaks the handle.

travis-ci: success for unix: don't leak a file descriptor
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 3649d94c
...@@ -881,16 +881,16 @@ static int prep_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, int *prev ...@@ -881,16 +881,16 @@ static int prep_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, int *prev
*prev_root_fd = open("/", O_RDONLY); *prev_root_fd = open("/", O_RDONLY);
if (*prev_root_fd < 0) { if (*prev_root_fd < 0) {
pr_err("Can't open current root\n"); pr_err("Can't open current root\n");
return -1; goto err;
} }
if (fchdir(root->mnt.root_fd)) { if (fchdir(root->mnt.root_fd)) {
pr_perror("Unable to change current working dir"); pr_perror("Unable to change current working dir");
return -1; goto err;
} }
if (chroot(".")) { if (chroot(".")) {
pr_perror("Unable to change root directory"); pr_perror("Unable to change root directory");
return -1; goto err;
} }
} }
...@@ -898,14 +898,17 @@ static int prep_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, int *prev ...@@ -898,14 +898,17 @@ static int prep_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, int *prev
if (chdir(ui->name_dir)) { if (chdir(ui->name_dir)) {
pr_perror("Can't change working dir %s", pr_perror("Can't change working dir %s",
ui->name_dir); ui->name_dir);
close(*prev_cwd_fd); goto err;
*prev_cwd_fd = -1;
return -1;
} }
pr_debug("Change working dir to %s\n", ui->name_dir); pr_debug("Change working dir to %s\n", ui->name_dir);
} }
return 0; return 0;
err:
close_safe(prev_cwd_fd);
if (prev_root_fd)
close_safe(prev_root_fd);
return -1;
} }
static int post_open_unix_sk(struct file_desc *d, int fd) static int post_open_unix_sk(struct file_desc *d, int fd)
......
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