{commands,start}: remove element from list first

First remove the client from the list then close the fd. Otherwise we open
ourselves to a race where another codepath might be writing to a bad file
descriptor.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2018-02-18 23:20:05 +01:00
parent 81084dbd0e
commit 300d1cb40a
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D
2 changed files with 2 additions and 2 deletions

View File

@ -1156,8 +1156,8 @@ static void lxc_cmd_fd_cleanup(int fd, struct lxc_handler *handler,
continue; continue;
/* kick client from list */ /* kick client from list */
close(client->clientfd);
lxc_list_del(cur); lxc_list_del(cur);
close(client->clientfd);
free(cur->elem); free(cur->elem);
free(cur); free(cur);
/* No need to walk the whole list. If we found the state client /* No need to walk the whole list. If we found the state client

View File

@ -427,8 +427,8 @@ int lxc_serve_state_clients(const char *name, struct lxc_handler *handler,
} }
/* kick client from list */ /* kick client from list */
close(client->clientfd);
lxc_list_del(cur); lxc_list_del(cur);
close(client->clientfd);
free(cur->elem); free(cur->elem);
free(cur); free(cur);
} }