From 95b3a8c8a82a34ca874ac0d4a9bbbdb38034acf3 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 13 Jan 2021 16:10:13 -0600 Subject: qapi: More complex uses of QAPI_LIST_APPEND These cases require a bit more thought to review; in each case, the code was appending to a list, but not with a FOOList **tail variable. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210113221013.390592-6-eblake@redhat.com> Reviewed-by: Markus Armbruster [Flawed change to qmp_guest_network_get_interfaces() dropped] Signed-off-by: Markus Armbruster --- ui/spice-core.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'ui') diff --git a/ui/spice-core.c b/ui/spice-core.c index 5746d0a..514c0f9 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -354,11 +354,11 @@ static const char *wan_compression_names[] = { static SpiceChannelList *qmp_query_spice_channels(void) { - SpiceChannelList *cur_item = NULL, *head = NULL; + SpiceChannelList *head = NULL, **tail = &head; ChannelList *item; QTAILQ_FOREACH(item, &channel_list, link) { - SpiceChannelList *chan; + SpiceChannel *chan; char host[NI_MAXHOST], port[NI_MAXSERV]; struct sockaddr *paddr; socklen_t plen; @@ -366,29 +366,22 @@ static SpiceChannelList *qmp_query_spice_channels(void) assert(item->info->flags & SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT); chan = g_malloc0(sizeof(*chan)); - chan->value = g_malloc0(sizeof(*chan->value)); paddr = (struct sockaddr *)&item->info->paddr_ext; plen = item->info->plen_ext; getnameinfo(paddr, plen, host, sizeof(host), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV); - chan->value->host = g_strdup(host); - chan->value->port = g_strdup(port); - chan->value->family = inet_netfamily(paddr->sa_family); - - chan->value->connection_id = item->info->connection_id; - chan->value->channel_type = item->info->type; - chan->value->channel_id = item->info->id; - chan->value->tls = item->info->flags & SPICE_CHANNEL_EVENT_FLAG_TLS; - - /* XXX: waiting for the qapi to support GSList */ - if (!cur_item) { - head = cur_item = chan; - } else { - cur_item->next = chan; - cur_item = chan; - } + chan->host = g_strdup(host); + chan->port = g_strdup(port); + chan->family = inet_netfamily(paddr->sa_family); + + chan->connection_id = item->info->connection_id; + chan->channel_type = item->info->type; + chan->channel_id = item->info->id; + chan->tls = item->info->flags & SPICE_CHANNEL_EVENT_FLAG_TLS; + + QAPI_LIST_APPEND(tail, chan); } return head; -- cgit v1.1