From: Gonglei <arei.gong...@huawei.com> 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 <pbonz...@redhat.com> Signed-off-by: Gonglei <arei.gong...@huawei.com> --- 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