mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-09-06 09:55:55 +00:00
qemu-char: avoid leaking unused fds in tcp_get_msgfds()
Commit c76bf6bb8f
("Add chardev API
qemu_chr_fe_get_msgfds") extended the get_msgfds API from one to
multiple file descriptors. It forgot to close unused file descriptors
before freeing the file descriptor array.
This patch prevents a file descriptor leak if the tcp_get_msgfds()
callers requests fewer file descriptors than are available.
Cc: Nikolay Nikolaev <n.nikolaev@virtualopensystems.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
4f85861441
commit
d2fc39b420
|
@ -2481,8 +2481,15 @@ static int tcp_get_msgfds(CharDriverState *chr, int *fds, int num)
|
|||
int to_copy = (s->read_msgfds_num < num) ? s->read_msgfds_num : num;
|
||||
|
||||
if (to_copy) {
|
||||
int i;
|
||||
|
||||
memcpy(fds, s->read_msgfds, to_copy * sizeof(int));
|
||||
|
||||
/* Close unused fds */
|
||||
for (i = to_copy; i < s->read_msgfds_num; i++) {
|
||||
close(s->read_msgfds[i]);
|
||||
}
|
||||
|
||||
g_free(s->read_msgfds);
|
||||
s->read_msgfds = 0;
|
||||
s->read_msgfds_num = 0;
|
||||
|
|
Loading…
Reference in a new issue