conf: ensure lxc_delete_tty() does not crash

We need to make sure that the ttys are actually initialized otherwise deleting them is not safe. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent f3815517
......@@ -968,6 +968,8 @@ int lxc_allocate_ttys(const char *name, struct lxc_conf *conf)
for (i = 0; i < ttys->max; i++) {
struct lxc_terminal_info *tty = &ttys->tty[i];
tty->master = -EBADF;
tty->slave = -EBADF;
ret = openpty(&tty->master, &tty->slave,
tty->name, NULL, NULL);
if (ret) {
......@@ -1004,11 +1006,21 @@ void lxc_delete_tty(struct lxc_tty_info *ttys)
{
int i;
if (!ttys->tty)
return;
for (i = 0; i < ttys->max; i++) {
struct lxc_terminal_info *tty = &ttys->tty[i];
close(tty->master);
close(tty->slave);
if (tty->master >= 0) {
close(tty->master);
tty->master = -EBADF;
}
if (tty->slave >= 0) {
close(tty->slave);
tty->slave = -EBADF;
}
}
free(ttys->tty);
......
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