[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] vnc: fix fd leak at vnc_display_open()
From: |
arei.gonglei |
Subject: |
[Qemu-devel] [PATCH] vnc: fix fd leak at vnc_display_open() |
Date: |
Thu, 23 Oct 2014 14:33:36 +0800 |
From: Gonglei <address@hidden>
When using qmp change vnc interface, will leak fd
of vs->lsock and vs->lwebsock (if configed). Close
them before: re-evaluate.
Signed-off-by: Gonglei <address@hidden>
---
This patch based on my just prvious vnc patch seires.
Easy to reproduce this leak:
$ ./qemu-system-x86_64 [...] -monitor stdio -vnc 0.0.0.0:10,password
(qemu) change vnc 0.0.0.0:11,password,sasl
(qemu)
Then using vnc client connet the vnc server with 'port 10', Qemu will hang.
---
ui/vnc.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/ui/vnc.c b/ui/vnc.c
index 8f2f277..1f25b51 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -3257,9 +3257,18 @@ void vnc_display_open(const char *display, Error **errp)
if (reverse) {
/* connect to viewer */
int csock;
- vs->lsock = -1;
+
+ if (vs->lsock != -1) {
+ qemu_set_fd_handler2(vs->lsock, NULL, NULL, NULL, NULL);
+ close(vs->lsock);
+ vs->lsock = -1;
+ }
#ifdef CONFIG_VNC_WS
- vs->lwebsock = -1;
+ if (vs->lwebsock != -1) {
+ qemu_set_fd_handler2(vs->lwebsock, NULL, NULL, NULL, NULL);
+ close(vs->lwebsock);
+ vs->lwebsock = -1;
+ }
#endif
if (strncmp(display, "unix:", 5) == 0) {
csock = unix_connect(display+5, errp);
@@ -3274,6 +3283,11 @@ void vnc_display_open(const char *display, Error **errp)
/* listen for connects */
char *dpy;
dpy = g_malloc(256);
+ if (vs->lsock != -1) {
+ qemu_set_fd_handler2(vs->lsock, NULL, NULL, NULL, NULL);
+ close(vs->lsock);
+ vs->lsock = -1;
+ }
if (strncmp(display, "unix:", 5) == 0) {
pstrcpy(dpy, 256, "unix:");
vs->lsock = unix_listen(display+5, dpy+5, 256-5, errp);
@@ -3286,6 +3300,11 @@ void vnc_display_open(const char *display, Error **errp)
}
#ifdef CONFIG_VNC_WS
if (vs->websocket) {
+ if (vs->lwebsock != -1) {
+ qemu_set_fd_handler2(vs->lwebsock, NULL, NULL, NULL, NULL);
+ close(vs->lwebsock);
+ vs->lwebsock = -1;
+ }
if (vs->ws_display) {
vs->lwebsock = inet_listen(vs->ws_display, NULL, 256,
SOCK_STREAM, 0, errp);
--
1.7.12.4
- [Qemu-devel] [PATCH] vnc: fix fd leak at vnc_display_open(),
arei.gonglei <=