[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] spice: fix memory leak
From: |
arei.gonglei |
Subject: |
[Qemu-devel] [PATCH] spice: fix memory leak |
Date: |
Fri, 5 Dec 2014 11:31:10 +0800 |
From: Gonglei <address@hidden>
If errors happen for middle items of channel_list,
qmp_query_spice_channels() return NULL, and varriable
cur_item going out of scope leaks the storage it points to.
Let's check for errors in advance avoid memory leak.
Suggested-by: Paolo Bonzini <address@hidden>
Signed-off-by: Gonglei <address@hidden>
---
ui/spice-core.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 6467fa4..8a74afe 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -381,15 +381,17 @@ static SpiceChannelList *qmp_query_spice_channels(void)
ChannelList *item;
QTAILQ_FOREACH(item, &channel_list, link) {
- SpiceChannelList *chan;
- char host[NI_MAXHOST], port[NI_MAXSERV];
- struct sockaddr *paddr;
- socklen_t plen;
-
if (!(item->info->flags & SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT)) {
error_report("invalid channel event");
return NULL;
}
+ }
+
+ QTAILQ_FOREACH(item, &channel_list, link) {
+ SpiceChannelList *chan;
+ char host[NI_MAXHOST], port[NI_MAXSERV];
+ struct sockaddr *paddr;
+ socklen_t plen;
chan = g_malloc0(sizeof(*chan));
chan->value = g_malloc0(sizeof(*chan->value));
--
1.7.12.4
- [Qemu-devel] [PATCH] spice: fix memory leak,
arei.gonglei <=