[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/23] qemu-char: avoid leaking unused fds in tcp_get
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 14/23] qemu-char: avoid leaking unused fds in tcp_get_msgfds() |
Date: |
Mon, 23 Jun 2014 18:53:55 +0300 |
From: Stefan Hajnoczi <address@hidden>
Commit c76bf6bb8fbbb233a7d3641e09229d23747d5ee3 ("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 <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
qemu-char.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/qemu-char.c b/qemu-char.c
index d9100a2..e6cbafb 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -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;
--
MST
- [Qemu-devel] [PULL 04/23] libqemustub: add more stubs for qemu-char, (continued)
- [Qemu-devel] [PULL 04/23] libqemustub: add more stubs for qemu-char, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 05/23] qtest: fix qtest for vhost-user, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 06/23] qtest: fix vhost-user-test unbalanced mutex locks, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 08/23] e1000: improve auto-negotiation reporting via mii-tool, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 07/23] e1000: emulate auto-negotiation during external link status change, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 09/23] e1000: signal guest on successful link auto-negotiation, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 10/23] e1000: move e1000_autoneg_timer() to after set_ics(), Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 11/23] e1000: factor out checking for auto-negotiation availability, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 13/23] qemu-char: fix qemu_chr_fe_get_msgfd(), Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 12/23] qapi/string-output-visitor: fix human output, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 14/23] qemu-char: avoid leaking unused fds in tcp_get_msgfds(),
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 15/23] virtio-pci: Report an error when msix vectors init fails, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 16/23] q35: Use PC_Q35_COMPAT_1_4 on pc-q35-1.4 compat_props, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 17/23] hw/pcie: correct debug message, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 18/23] hw/pcie: implement power controller functionality, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 19/23] hw/pcie: better hotplug/hotunplug support, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 20/23] pcie: coding style tweak, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 22/23] pc & q35: Add new machine opt max-ram-below-4g, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 21/23] xen-hvm: Fix xen_hvm_init() to adjust pc memory layout, Michael S. Tsirkin, 2014/06/23
- [Qemu-devel] [PULL 23/23] xen-hvm: Handle machine opt max-ram-below-4g, Michael S. Tsirkin, 2014/06/23
- Re: [Qemu-devel] [PULL 00/23] pc,pci,vhost,net fixes, enhancements, Peter Maydell, 2014/06/24