From nobody Sat May 4 02:44:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 147974332196396.68203702997312; Mon, 21 Nov 2016 07:48:41 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id uALFjFpC020975; Mon, 21 Nov 2016 10:45:15 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id uALFjDcK013249 for ; Mon, 21 Nov 2016 10:45:13 -0500 Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uALFjDoT001211 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Mon, 21 Nov 2016 10:45:13 -0500 Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68EF431B323 for ; Mon, 21 Nov 2016 15:45:12 +0000 (UTC) Received: by mail-qt0-f194.google.com with SMTP id n6so25790934qtd.0 for ; Mon, 21 Nov 2016 07:45:12 -0800 (PST) Received: from kloomba.my.domain ([213.147.221.120]) by smtp.gmail.com with ESMTPSA id 26sm5429919ljo.24.2016.11.21.07.45.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Nov 2016 07:45:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=WWk5BcqAu/iCYnfrJC+/C4GFnEIqoBt0z8lTBlM157w=; b=ICNnJ/uXuaae0zsc0UcyGK2jXppLhOW/bPxzuD5JnFr7WuBcDqT0TnOI4jZvuQ9OuM 4Dk29SH/ZQqk/LGAy3fubCEd6Gw4XddW3TXRMCeYrlcI30+W975tZhPyjgE3tbNKhC+H Y/VtYfJKgg0v/Rekj0lmnMl/2joc9eI+iQ/N4nIgw8uc1/8qetrc7TVEQt46BjE4aioQ J+VXo7oeo31gMtsaE880x/HPY02j1DdmMy3vPGb0eQtiFGW8qgR+IxN6QEV6ijM9q5bA zwwIBzp1YqiXwJj8uF7DR12vFiIjVW90XZpLnSuWckjp+2NRcV2moTgljCBUvcTxgfeV VxFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WWk5BcqAu/iCYnfrJC+/C4GFnEIqoBt0z8lTBlM157w=; b=GbZZaoqVySamEAn82p2mNdYTMZAK38SEMdWHmsR2fPOC9p6YGoaf5G3RA+p1PXRB4v wFPX4LzqgmGK4iksdS67xIxVbzBA6EYwhTVABzpV6QNnnh6bjaIwJnCgMf+YH3DHmNnw XU5ZunUDRY/TsIkKnl6ePg0DVTRZ2T1PSaAq/FO1X1oPE9Chev6n2vZNQ3iDb8GAG7mz 9w78wx/NlWd1HB2r0E7bb4peXBHKhUGjHkfsinwXb4HQ24a8KEskeQhL0ysrnYhnhiOA kIg2QBt3vvEDqPoP1enLjcaeKqkJbJurJ3EJRIE7wS3cOuIBA5/Gee7Q4sC0YLN3IyRx atlQ== X-Gm-Message-State: AKaTC011HIFZGFASbNEW/LHCEMp5vxlL1wqSGXddbIzcV9HjG6l1nXOtDJS4Hj3Ul2Mkmg== X-Received: by 10.25.215.102 with SMTP id o99mr3266868lfg.57.1479743111206; Mon, 21 Nov 2016 07:45:11 -0800 (PST) From: Roman Bogorodskiy To: libvirt-list@redhat.com Date: Mon, 21 Nov 2016 18:45:05 +0300 Message-Id: <20161121154505.44172-1-bogorodskiy@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 21 Nov 2016 15:45:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 21 Nov 2016 15:45:12 +0000 (UTC) for IP:'209.85.216.194' DOMAIN:'mail-qt0-f194.google.com' HELO:'mail-qt0-f194.google.com' FROM:'bogorodskiy@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.67 (BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.216.194 mail-qt0-f194.google.com 209.85.216.194 mail-qt0-f194.google.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-loop: libvir-list@redhat.com Cc: Roman Bogorodskiy Subject: [libvirt] [PATCH] bhyve: cleanup bhyveBuildNetArgStr error handling X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_1 Z_629926901 SPT_1 UDT_7 RF_0 X-Zoho-Virus-Status: 2 Content-Type: text/plain; charset="utf-8" Use 'goto cleanup'-style error handling instead of explicitly freeing variables in every error path. --- src/bhyve/bhyve_command.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 022b03b..4914d98 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -52,26 +52,25 @@ bhyveBuildNetArgStr(const virDomainDef *def, char macaddr[VIR_MAC_STRING_BUFLEN]; char *realifname =3D NULL; char *brname =3D NULL; + int ret =3D -1; virDomainNetType actualType =3D virDomainNetGetActualType(net); =20 if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE) { if (VIR_STRDUP(brname, virDomainNetGetActualBridgeName(net)) < 0) - return -1; + goto cleanup; } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Network type %d is not supported"), virDomainNetGetActualType(net)); - return -1; + goto cleanup; } =20 if (!net->ifname || STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) || strchr(net->ifname, '%')) { VIR_FREE(net->ifname); - if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_PREFIX "%d") < 0) { - VIR_FREE(brname); - return -1; - } + if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_PREFIX "%d") < 0) + goto cleanup; } =20 if (!dryRun) { @@ -80,33 +79,24 @@ bhyveBuildNetArgStr(const virDomainDef *def, virDomainNetGetActualVirtPortPr= ofile(net), virDomainNetGetActualVlan(net), VIR_NETDEV_TAP_CREATE_IFUP | VI= R_NETDEV_TAP_CREATE_PERSIST) < 0) { - VIR_FREE(net->ifname); - VIR_FREE(brname); - return -1; + goto cleanup; } =20 realifname =3D virNetDevTapGetRealDeviceName(net->ifname); =20 - if (realifname =3D=3D NULL) { - VIR_FREE(net->ifname); - VIR_FREE(brname); - return -1; - } + if (realifname =3D=3D NULL) + goto cleanup; =20 VIR_DEBUG("%s -> %s", net->ifname, realifname); /* hack on top of other hack: we need to set * interface to 'UP' again after re-opening to find its * name */ - if (virNetDevSetOnline(net->ifname, true) !=3D 0) { - VIR_FREE(realifname); - VIR_FREE(net->ifname); - VIR_FREE(brname); - return -1; - } + if (virNetDevSetOnline(net->ifname, true) !=3D 0) + goto cleanup; } else { if (VIR_STRDUP(realifname, "tap0") < 0) - return -1; + goto cleanup; } =20 =20 @@ -114,9 +104,14 @@ bhyveBuildNetArgStr(const virDomainDef *def, virCommandAddArgFormat(cmd, "%d:0,virtio-net,%s,mac=3D%s", net->info.addr.pci.slot, realifname, virMacAddrFormat(&net->mac, macaddr= )); + + ret =3D 0; + cleanup: + VIR_FREE(brname); + VIR_FREE(net->ifname); VIR_FREE(realifname); =20 - return 0; + return ret; } =20 static int --=20 2.10.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list