From patchwork Tue Jan 18 16:09:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12716677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1BC42C433EF for ; Tue, 18 Jan 2022 16:21:17 +0000 (UTC) Received: from localhost ([::1]:57106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n9rER-00027L-S6 for qemu-devel@archiver.kernel.org; Tue, 18 Jan 2022 11:21:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9r37-0003WL-Dg for qemu-devel@nongnu.org; Tue, 18 Jan 2022 11:09:33 -0500 Received: from mail-db8eur05on2108.outbound.protection.outlook.com ([40.107.20.108]:18657 helo=EUR05-DB8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9r34-0000PK-Fl for qemu-devel@nongnu.org; Tue, 18 Jan 2022 11:09:32 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AVIZ8gE/4+I9pfsHdVxvLIdoEnd32Fa8hFQPRftSzknx82BzECQyiNW39lqPcRK4LShiEQoTkK3BW/d1fMNkh9pbGXrsT8ml4Z3uFfkRm6H3Qt8nUVq92rKFSfB/V9LYF0sDVqNntbAkdIetK+UBZZBxYg/oOzCV1R5YfFyqkZWIc+KpehVF45TT8T1ivFmWAjAnV6sFixqmHTMGFbAYMvgPgua357v7LfZW0jaTHOe0tipBOYqbvVjop1X+A0jfwWUVyofT4TjJnSVvUDCqGF9Ctt34vP89SntjF2AyhOlOfgk3bVNMGhPbAarmAZil8FBQM12ASWsSuGAJ5p01ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7hh2PRLmUmjZ26xsg29vPn8mXmfObsC/LzeFTayHCok=; b=EM3cFcTPAsgyseGSZWCx9UH0F4gE5qlJC5yhUdDpUQA0xoquIUrOmzPA4tT6N49j8da6vLgQx1Jwnf5YAKte+6I0g4/uoF36IUi5t190xnc87r89Z6T59xY1Z5zt2pLSlhXo/Ha7Xc1qqA19/PUxQ7NEsi31wxZgmAIy+kKZ0IZ8AoFT2SfIRfNQhBC6yBL61waFc5Vzo6SWwExw8oax+Ik9mA1LsrSEqgk6KseRQQz5aIFbbvhvsK2hKoPAAwCzsuNSih1AUL6KaknBQcAC/2vJbLo167BwWjQBTpbgHtPy6IBOyNQaV7GRiyM0PRPamEIxXQwqfsAYoHpU6uQppw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7hh2PRLmUmjZ26xsg29vPn8mXmfObsC/LzeFTayHCok=; b=IqXeGe0+raILO8ORUhhnCxR9o2HNpjk5VqLm3kkUHahH7zO8YJ2ySaxH9x863pB9GgyPneefk1OFkZ+eEde+VfFuWRk7X6F7CtaLv1SkE9R0GC9Zv9EFktHSq6EPZ5umJXc1sN5tRe51IGX4lqhGjCb0rswOnRoRhn6ZqTgT86I= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM0PR08MB3953.eurprd08.prod.outlook.com (2603:10a6:208:125::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.10; Tue, 18 Jan 2022 16:09:26 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::b435:c0de:ef6b:5917]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::b435:c0de:ef6b:5917%7]) with mapi id 15.20.4888.014; Tue, 18 Jan 2022 16:09:26 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: bleal@redhat.com, wainersm@redhat.com, f4bug@amsat.org, crosa@redhat.com, eblake@redhat.com, armbru@redhat.com, kraxel@redhat.com, berrange@redhat.com, vsementsov@virtuozzo.com, marcandre.lureau@redhat.com Subject: [PATCH v3 1/3] ui/vnc: refactor arrays of addresses to SocketAddressList Date: Tue, 18 Jan 2022 17:09:07 +0100 Message-Id: <20220118160909.2502374-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220118160909.2502374-1-vsementsov@virtuozzo.com> References: <20220118160909.2502374-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM7PR03CA0006.eurprd03.prod.outlook.com (2603:10a6:20b:130::16) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5fee97db-506e-43e7-c3f2-08d9da9ce612 X-MS-TrafficTypeDiagnostic: AM0PR08MB3953:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:454; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 72rzlETaF4shwVKCL+K5cO022b3WoMRcafWo8YQcxwawqoOuSlJptkR1XjtVTSAPYweIjbCiEd4wvhwDL8rptJjLMS6xRr/lZ+sUdh8WUzGPR2jqPnxkpI5eNPIcLE4dfmZg1mO1EVUA5DvTnndlTtLt+iQGTboeILDd0OJNpjfCfBYZcmP/S+0n+p7mp0t31946AwephnjhYb4ZICzUxRmUodYAYbUCGfaZhNG0CxHCcOuI7c1D2Pe16rP6jLhQoQwPjyYY1Dhd2xBNRVT+0qVJluqUM/5xJ5ndR3WtlM8CgHXDt/OYn65yqvyU7Z8H4tikZV/Y5L2uKTuBGlKsX4CMTCLt8Md9ZgqF87aIkeT9psTWAGieRYcLTVSXs5c7R6xps/a6WHk//nVc2JAldIwIjBY4aTS8rymQVffwQv78xTrrJiO37iuHGQUHrCgMCyYk9c8OSve8hITKwfgDxoKUfKhwyHNlCaFSS5jaeqrToyAB6nzCp5iYIDSrSODz+1Wcs/hN8ozzG+3B27EnlH4EhnNXgO9Z4QwOTqHzmFWkvk7ofLkhVCXNl8zVQOUP+cayKmwZbrnauKSvucWHksFkJG7yj0RojAoGpMFZDTtWiuYB9hsW+ST85Am1BT9sy/2F+oiEKPdBlZm9NGIHfUCFWyIme5bsgaZv2sbqsetWni66TqBPqm1cAyI7Pdn6UY5r6otuNYQ0SYIKZfRjKQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(52116002)(2616005)(1076003)(66946007)(8676002)(186003)(6506007)(5660300002)(66556008)(38350700002)(4326008)(66476007)(8936002)(26005)(6486002)(86362001)(316002)(6512007)(6666004)(83380400001)(2906002)(38100700002)(508600001)(6916009)(7416002)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?hFkx7H/m4Sgy4/DJh9lgDzPXTazT?= =?utf-8?q?PwWnwXSKcMlpDB+HTavIQeRLENCKG9sP84MDIrX83W1wUJxl5DMgv6fBldDN/6v6u?= =?utf-8?q?g1qHbALDYBgmDck3m69l90jhVQZQZuNmo/ZxGP87jzM3vKmQiHYQeZcRSThK4PWex?= =?utf-8?q?D2nI0cRq+XClaLJ61zm9MR5xhByUzC/dt7WC93zy7/Bhzp5GtT2dWIJi0WgkK8kkR?= =?utf-8?q?ZSfOaETxUxEm89EeWpSnMro+ZauE7b76oABqvhnXI/sXCaVhb4ftYG69b3Rf8n2jO?= =?utf-8?q?9LsaY7L9yrhdHm79ABS+FujOBZnpvpi+ioGFWmMDi2eDo3p5DS3ctLcE4oPtPi428?= =?utf-8?q?QOmhfdcsy6ouwv/Bhnn6ArhBfOIB8UwKxW/F5Cb+PYEmlG5qSlyF2WKVhPPMqL99P?= =?utf-8?q?qXhlBBlvJcOLDFNdECqAnaX40kmY0UW4LrowZBQnPRaRCZH9n0olp4x3aNhHLLGtq?= =?utf-8?q?BLT2yUdS1MQ2pjr66lZ2lhZPJYsSQ69SypNlGETkA2D5yggf6uccHFBAdYj7PbsHM?= =?utf-8?q?C6OXavaVoebnHmqw7jvfkfE88rnPpQXcj96v07j6ECN3ryhLirx5emelzDY/3P+LE?= =?utf-8?q?B42O1IEe3jz9BR5E94aSYucx/iHB+lzqTSg5oa28i/diAaXqFA/GI2BbEvFa93Dph?= =?utf-8?q?uKlJRM37WtHuuoUUIIZ04fhh+PcfuknQtblfXXtj17H4iGN+3mxy5O3+hj0IbszVe?= =?utf-8?q?h5T3UU0nNg0AXa8xDtSNLFlAKU8PgI3nm6Tr/mzMdlfzuaF11uLITHhZ+fx4dOy6Y?= =?utf-8?q?ZBVQU9MFT7tt5fBk8hDExh2InWTgXl5EnXgiLrGWYifalqXYHD+z9i4V0vgxuHKaQ?= =?utf-8?q?FnTVFHzAR3jLbHV7DFKJBKxkGF/nSILaGD9gbczlwKNVRtva1gSK+jSEQFWituXhO?= =?utf-8?q?XBiFzuNQc6DsyzwtIXk5CL38Yy8IEcdgdN776fR63IGZmmXGeCBWRf1IL0Hgyk/d6?= =?utf-8?q?UhW9NpGG8s7xcDurAzWUCkc7pKCi68O95uCsLFuN6nqXHL9D0Cm4rn3RQjFiw0Qew?= =?utf-8?q?l1sCE0t0O6fIV+FsKBx6ZCt46FGp5cSCfqwNjMmgoWygqoXmTT+z2+bRGhUNNJ645?= =?utf-8?q?fposWiIefN8wQtAWXfrE9eJ1rgNnC/TzVic9N0aRChifaFWqLH96T7P/98Uma67qL?= =?utf-8?q?V6mOY/csgGX5kb5vXG2Df/hg3w0256UoRlqnqeoGA9bwHRMkP+BT3APSvHvfEL5Lf?= =?utf-8?q?gIS3svz2Nty9w850Amdw2HhDEHYm1179Yd4qACibA0Hf8penChojGN29sUeoXhCkP?= =?utf-8?q?PEKjyo7NT9f595vS3EjEoVfNJCHj473lGlagWYI1w5I5Ju+zc+bFCA77heaXjWkPc?= =?utf-8?q?aa/jgFcikeUE6xXkvYQ6XeQPBy6N1zPTpBht/nuAZKX//cFH8TACPUHlDykc0OIOC?= =?utf-8?q?tC7OtBpAxNg4n4FvWMk+5k7iIh557lb7Y+iKHLM31nMfHorzee+i0EETeqNqSpn3W?= =?utf-8?q?zuAb9E5Z0ZrBcwZRPvzmzaa+TtL+dvewJY49fesPhNhOAUjoAGz8YDPtOiHt+Q+dt?= =?utf-8?q?+kSPojgKWsMKrLYm/H5iEI5C/vG5IwPlOMOWXsjvRHJKRYAZJOgrWPlLf+CxqqwQx?= =?utf-8?q?0QQnHFGxgJ6lj33Fy4nYrb8ecNH7II85kr83sHFot7bkBpxOyljRO4=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5fee97db-506e-43e7-c3f2-08d9da9ce612 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2022 16:09:26.4065 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7N8HhptquOFf8AadINjjIAB1V02E3Ro9i59bm20oMTsfff2D1F5XeNa6ZwRMxwcTmwBH6PY3lZIoZdRW8LJq3ZuHksXyJS4wvjzAyx+2DN0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3953 Received-SPF: pass client-ip=40.107.20.108; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-DB8-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Let's use SocketAddressList instead of dynamic arrays. Benefits: - Automatic cleanup: don't need specific freeing function and drop some gotos. - Less indirection: no triple asterix anymore! - Prepare for the following commit, which will reuse new interface of vnc_display_listen(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Marc-André Lureau Reviewed-by: Daniel P. Berrangé --- ui/vnc.c | 129 ++++++++++++++++++++++--------------------------------- 1 file changed, 51 insertions(+), 78 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 3ccd33dedc..fa0fb736d3 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3812,30 +3812,19 @@ static int vnc_display_get_address(const char *addrstr, return ret; } -static void vnc_free_addresses(SocketAddress ***retsaddr, - size_t *retnsaddr) -{ - size_t i; - - for (i = 0; i < *retnsaddr; i++) { - qapi_free_SocketAddress((*retsaddr)[i]); - } - g_free(*retsaddr); - - *retsaddr = NULL; - *retnsaddr = 0; -} - static int vnc_display_get_addresses(QemuOpts *opts, bool reverse, - SocketAddress ***retsaddr, - size_t *retnsaddr, - SocketAddress ***retwsaddr, - size_t *retnwsaddr, + SocketAddressList **saddr_list_ret, + SocketAddressList **wsaddr_list_ret, Error **errp) { SocketAddress *saddr = NULL; SocketAddress *wsaddr = NULL; + g_autoptr(SocketAddressList) saddr_list = NULL; + SocketAddressList **saddr_tail = &saddr_list; + SocketAddress *single_saddr = NULL; + g_autoptr(SocketAddressList) wsaddr_list = NULL; + SocketAddressList **wsaddr_tail = &wsaddr_list; QemuOptsIter addriter; const char *addr; int to = qemu_opt_get_number(opts, "to", 0); @@ -3844,23 +3833,16 @@ static int vnc_display_get_addresses(QemuOpts *opts, bool ipv4 = qemu_opt_get_bool(opts, "ipv4", false); bool ipv6 = qemu_opt_get_bool(opts, "ipv6", false); int displaynum = -1; - int ret = -1; - - *retsaddr = NULL; - *retnsaddr = 0; - *retwsaddr = NULL; - *retnwsaddr = 0; addr = qemu_opt_get(opts, "vnc"); if (addr == NULL || g_str_equal(addr, "none")) { - ret = 0; - goto cleanup; + return 0; } if (qemu_opt_get(opts, "websocket") && !qcrypto_hash_supports(QCRYPTO_HASH_ALG_SHA1)) { error_setg(errp, "SHA1 hash support is required for websockets"); - goto cleanup; + return -1; } qemu_opt_iter_init(&addriter, opts, "vnc"); @@ -3871,7 +3853,7 @@ static int vnc_display_get_addresses(QemuOpts *opts, ipv4, ipv6, &saddr, errp); if (rv < 0) { - goto cleanup; + return -1; } /* Historical compat - first listen address can be used * to set the default websocket port @@ -3879,13 +3861,16 @@ static int vnc_display_get_addresses(QemuOpts *opts, if (displaynum == -1) { displaynum = rv; } - *retsaddr = g_renew(SocketAddress *, *retsaddr, *retnsaddr + 1); - (*retsaddr)[(*retnsaddr)++] = saddr; + QAPI_LIST_APPEND(saddr_tail, saddr); } - /* If we had multiple primary displays, we don't do defaults - * for websocket, and require explicit config instead. */ - if (*retnsaddr > 1) { + if (saddr_list && !saddr_list->next) { + single_saddr = saddr_list->value; + } else { + /* + * If we had multiple primary displays, we don't do defaults + * for websocket, and require explicit config instead. + */ displaynum = -1; } @@ -3895,57 +3880,50 @@ static int vnc_display_get_addresses(QemuOpts *opts, has_ipv4, has_ipv6, ipv4, ipv6, &wsaddr, errp) < 0) { - goto cleanup; + return -1; } /* Historical compat - if only a single listen address was * provided, then this is used to set the default listen * address for websocket too */ - if (*retnsaddr == 1 && - (*retsaddr)[0]->type == SOCKET_ADDRESS_TYPE_INET && + if (single_saddr && + single_saddr->type == SOCKET_ADDRESS_TYPE_INET && wsaddr->type == SOCKET_ADDRESS_TYPE_INET && g_str_equal(wsaddr->u.inet.host, "") && - !g_str_equal((*retsaddr)[0]->u.inet.host, "")) { + !g_str_equal(single_saddr->u.inet.host, "")) { g_free(wsaddr->u.inet.host); - wsaddr->u.inet.host = g_strdup((*retsaddr)[0]->u.inet.host); + wsaddr->u.inet.host = g_strdup(single_saddr->u.inet.host); } - *retwsaddr = g_renew(SocketAddress *, *retwsaddr, *retnwsaddr + 1); - (*retwsaddr)[(*retnwsaddr)++] = wsaddr; + QAPI_LIST_APPEND(wsaddr_tail, wsaddr); } - ret = 0; - cleanup: - if (ret < 0) { - vnc_free_addresses(retsaddr, retnsaddr); - vnc_free_addresses(retwsaddr, retnwsaddr); - } - return ret; + *saddr_list_ret = g_steal_pointer(&saddr_list); + *wsaddr_list_ret = g_steal_pointer(&wsaddr_list); + return 0; } static int vnc_display_connect(VncDisplay *vd, - SocketAddress **saddr, - size_t nsaddr, - SocketAddress **wsaddr, - size_t nwsaddr, + SocketAddressList *saddr_list, + SocketAddressList *wsaddr_list, Error **errp) { /* connect to viewer */ QIOChannelSocket *sioc = NULL; - if (nwsaddr != 0) { + if (wsaddr_list) { error_setg(errp, "Cannot use websockets in reverse mode"); return -1; } - if (nsaddr != 1) { + if (!saddr_list || saddr_list->next) { error_setg(errp, "Expected a single address in reverse mode"); return -1; } /* TODO SOCKET_ADDRESS_TYPE_FD when fd has AF_UNIX */ - vd->is_unix = saddr[0]->type == SOCKET_ADDRESS_TYPE_UNIX; + vd->is_unix = saddr_list->value->type == SOCKET_ADDRESS_TYPE_UNIX; sioc = qio_channel_socket_new(); qio_channel_set_name(QIO_CHANNEL(sioc), "vnc-reverse"); - if (qio_channel_socket_connect_sync(sioc, saddr[0], errp) < 0) { + if (qio_channel_socket_connect_sync(sioc, saddr_list->value, errp) < 0) { object_unref(OBJECT(sioc)); return -1; } @@ -3956,20 +3934,18 @@ static int vnc_display_connect(VncDisplay *vd, static int vnc_display_listen(VncDisplay *vd, - SocketAddress **saddr, - size_t nsaddr, - SocketAddress **wsaddr, - size_t nwsaddr, + SocketAddressList *saddr_list, + SocketAddressList *wsaddr_list, Error **errp) { - size_t i; + SocketAddressList *el; - if (nsaddr) { + if (saddr_list) { vd->listener = qio_net_listener_new(); qio_net_listener_set_name(vd->listener, "vnc-listen"); - for (i = 0; i < nsaddr; i++) { + for (el = saddr_list; el; el = el->next) { if (qio_net_listener_open_sync(vd->listener, - saddr[i], 1, + el->value, 1, errp) < 0) { return -1; } @@ -3979,12 +3955,12 @@ static int vnc_display_listen(VncDisplay *vd, vnc_listen_io, vd, NULL); } - if (nwsaddr) { + if (wsaddr_list) { vd->wslistener = qio_net_listener_new(); qio_net_listener_set_name(vd->wslistener, "vnc-ws-listen"); - for (i = 0; i < nwsaddr; i++) { + for (el = wsaddr_list; el; el = el->next) { if (qio_net_listener_open_sync(vd->wslistener, - wsaddr[i], 1, + el->value, 1, errp) < 0) { return -1; } @@ -4002,8 +3978,8 @@ void vnc_display_open(const char *id, Error **errp) { VncDisplay *vd = vnc_display_find(id); QemuOpts *opts = qemu_opts_find(&qemu_vnc_opts, id); - SocketAddress **saddr = NULL, **wsaddr = NULL; - size_t nsaddr, nwsaddr; + g_autoptr(SocketAddressList) saddr_list = NULL; + g_autoptr(SocketAddressList) wsaddr_list = NULL; const char *share, *device_id; QemuConsole *con; bool password = false; @@ -4028,8 +4004,8 @@ void vnc_display_open(const char *id, Error **errp) } reverse = qemu_opt_get_bool(opts, "reverse", false); - if (vnc_display_get_addresses(opts, reverse, &saddr, &nsaddr, - &wsaddr, &nwsaddr, errp) < 0) { + if (vnc_display_get_addresses(opts, reverse, &saddr_list, &wsaddr_list, + errp) < 0) { goto fail; } @@ -4211,16 +4187,16 @@ void vnc_display_open(const char *id, Error **errp) } qkbd_state_set_delay(vd->kbd, key_delay_ms); - if (saddr == NULL) { - goto cleanup; + if (saddr_list == NULL) { + return; } if (reverse) { - if (vnc_display_connect(vd, saddr, nsaddr, wsaddr, nwsaddr, errp) < 0) { + if (vnc_display_connect(vd, saddr_list, wsaddr_list, errp) < 0) { goto fail; } } else { - if (vnc_display_listen(vd, saddr, nsaddr, wsaddr, nwsaddr, errp) < 0) { + if (vnc_display_listen(vd, saddr_list, wsaddr_list, errp) < 0) { goto fail; } } @@ -4229,14 +4205,11 @@ void vnc_display_open(const char *id, Error **errp) vnc_display_print_local_addr(vd); } - cleanup: - vnc_free_addresses(&saddr, &nsaddr); - vnc_free_addresses(&wsaddr, &nwsaddr); + /* Success */ return; fail: vnc_display_close(vd); - goto cleanup; } void vnc_display_add_client(const char *id, int csock, bool skipauth)