From nobody Tue May 7 03:28:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714205002321.3472413015361; Wed, 8 Aug 2018 00:43:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A702080F7A; Wed, 8 Aug 2018 07:43:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 69C023001A5A; Wed, 8 Aug 2018 07:43:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1FF5918037ED; Wed, 8 Aug 2018 07:43:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hCDg005462 for ; Wed, 8 Aug 2018 03:43:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id A2F4938194; Wed, 8 Aug 2018 07:43:12 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9BA8D38195 for ; Wed, 8 Aug 2018 07:43:10 +0000 (UTC) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 2D1B9308402D for ; Wed, 8 Aug 2018 07:43:09 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id y5-v6so699839pgv.1 for ; Wed, 08 Aug 2018 00:43:09 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=8YTHdBQLqE2bhawyT8ndL8eB8737FB6vsY3DZQ8LXd0=; b=SgZ59k8ucc0y/k2POoMxzKCX1PfcEP+EywNbgn2J3OTXMVSJ/DT37a7G8cs5cvF2s2 YTjrt7btIFT4K4TSvqtO/9z8QfHbHar87yzQQnKTIOHzEnTcQHXaxPcGUiHzYcO2sjug 7kBXSFrwGUwwbFAtn1AesiF6A5pysrVrMzqnAHe/hSYO1+gc7ooeAqaJfV9e5jmmMrVq gknBsiUxTGhkZPWP6I/5OVToCJDi0PD9LDINO8Xs4vv9y1FZ+YAr81HDZ2/3yLjGfnVt JM7l1i7FHuRTS9AyWHnWsxJ4U1lmf0/MFpIuSpMBKe3fRXI4+FHftOPq6Ho7g/UGOO8S VesA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=8YTHdBQLqE2bhawyT8ndL8eB8737FB6vsY3DZQ8LXd0=; b=Iy26mhcYdSCjxjd1TzPIKOKhTySjqRXyvG35YFKVpkcpD0TWWnh08y4iqdBeeSfuX9 /kM1TL1rNHHj34N4xqOazuRe7ZScLttXdSqWkxyXlTIpeQ4pZGlypZbf7C7WKhBRMqex P+sS56RYBWbOYq8J6zCLx6EfJJmysTWPBjIXdMScSlwEmmlF901zN+IGR0DCmvn6FWjF ljCWrkZZTystW3gacn7w2j31rdGB6nQ0t7n0XdZGiUSTyefJ4VJYT+WA3zRMYkyITbDb 4+tTUWwvH8E+kj/P69QjA+N+h67SdCjM/ymf465KHZVk3Toyn3IUQK9BGuq3PrbBz2Ve ZSqg== X-Gm-Message-State: AOUpUlF92F5vyMm0DDlbU/eok/Ay6StNArqT58D5mc1jmId01XeIl98d udSb/v2Z/OG13wXp8n4xCtBRyeJf X-Google-Smtp-Source: AA+uWPwd2SnH1MAWcUdSiFilhTYGt6EPna34+mjMBjGR7IBvhcobOOuqj70JVLzoeKkewXvkn7TW9g== X-Received: by 2002:a62:6003:: with SMTP id u3-v6mr1732713pfb.114.1533714188390; Wed, 08 Aug 2018 00:43:08 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:28 +0530 Message-Id: <1533501842-24503-2-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 08 Aug 2018 07:43:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 08 Aug 2018 07:43:09 +0000 (UTC) for IP:'209.85.215.171' DOMAIN:'mail-pg1-f171.google.com' HELO:'mail-pg1-f171.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.215.171 mail-pg1-f171.google.com 209.85.215.171 mail-pg1-f171.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 01/35] util: iscsi: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 08 Aug 2018 07:43:23 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/viriscsi.c | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index f00aeb5..0c2d8bb 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -88,8 +88,8 @@ virISCSIGetSession(const char *devpath, .session =3D NULL, .devpath =3D devpath, }; - char *error =3D NULL; int exitstatus =3D 0; + VIR_AUTOFREE(char *) error =3D NULL; =20 virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "session", NULL); @@ -109,7 +109,6 @@ virISCSIGetSession(const char *devpath, NULLSTR(error)); =20 cleanup: - VIR_FREE(error); virCommandFree(cmd); return cbdata.session; } @@ -125,12 +124,11 @@ virStorageBackendIQNFound(const char *initiatoriqn, char **ifacename) { int ret =3D IQN_ERROR; - char *outbuf =3D NULL; char *line =3D NULL; - char *iface =3D NULL; - char *iqn =3D NULL; virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "iface", NULL); + VIR_AUTOFREE(char *) outbuf =3D NULL; + VIR_AUTOFREE(char *) iqn =3D NULL; =20 *ifacename =3D NULL; =20 @@ -150,13 +148,13 @@ virStorageBackendIQNFound(const char *initiatoriqn, char *newline; char *next; size_t i; + VIR_AUTOFREE(char *) iface =3D NULL; =20 if (!(newline =3D strchr(line, '\n'))) break; =20 *newline =3D '\0'; =20 - VIR_FREE(iface); VIR_FREE(iqn); =20 /* Find the first space, copy everything up to that point into @@ -197,9 +195,6 @@ virStorageBackendIQNFound(const char *initiatoriqn, if (ret =3D=3D IQN_MISSING) VIR_DEBUG("Could not find interface with IQN '%s'", iqn); =20 - VIR_FREE(iqn); - VIR_FREE(iface); - VIR_FREE(outbuf); virCommandFree(cmd); return ret; =20 @@ -216,8 +211,9 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, char **ifacename) { int ret =3D -1, exitstatus =3D -1; - char *temp_ifacename; virCommandPtr cmd =3D NULL; + VIR_AUTOFREE(char *) iface_name =3D NULL; + VIR_AUTOFREE(char *) temp_ifacename =3D NULL; =20 if (virAsprintf(&temp_ifacename, "libvirt-iface-%08llx", @@ -263,23 +259,23 @@ virStorageBackendCreateIfaceIQN(const char *initiator= iqn, } =20 /* Check again to make sure the interface was created. */ - if (virStorageBackendIQNFound(initiatoriqn, ifacename) !=3D IQN_FOUND)= { + if (virStorageBackendIQNFound(initiatoriqn, &iface_name) !=3D IQN_FOUN= D) { VIR_DEBUG("Failed to find interface '%s' with IQN '%s' " "after attempting to create it", &temp_ifacename[0], initiatoriqn); goto cleanup; } else { VIR_DEBUG("Interface '%s' with IQN '%s' was created successfully", - *ifacename, initiatoriqn); + iface_name, initiatoriqn); } =20 - ret =3D 0; + VIR_STEAL_PTR(*ifacename, iface_name); + + virCommandFree(cmd); + return 0; =20 cleanup: virCommandFree(cmd); - VIR_FREE(temp_ifacename); - if (ret !=3D 0) - VIR_FREE(*ifacename); return ret; } =20 @@ -299,7 +295,7 @@ virISCSIConnection(const char *portal, NULL }; virCommandPtr cmd; - char *ifacename =3D NULL; + VIR_AUTOFREE(char *) ifacename =3D NULL; =20 cmd =3D virCommandNewArgs(baseargv); virCommandAddArgSet(cmd, extraargv); @@ -339,7 +335,6 @@ virISCSIConnection(const char *portal, =20 cleanup: virCommandFree(cmd); - VIR_FREE(ifacename); =20 return ret; } @@ -390,15 +385,13 @@ virISCSIGetTargets(char **const groups, void *data) { struct virISCSITargetList *list =3D data; - char *target; + VIR_AUTOFREE(char *) target =3D NULL; =20 if (VIR_STRDUP(target, groups[1]) < 0) return -1; =20 - if (VIR_APPEND_ELEMENT(list->targets, list->ntargets, target) < 0) { - VIR_FREE(target); + if (VIR_APPEND_ELEMENT(list->targets, list->ntargets, target) < 0) return -1; - } =20 return 0; } @@ -498,8 +491,7 @@ virISCSIScanTargets(const char *portal, size_t *ntargets, char ***targets) { - char *ifacename =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) ifacename =3D NULL; =20 if (ntargets) *ntargets =3D 0; @@ -522,10 +514,8 @@ virISCSIScanTargets(const char *portal, } } =20 - ret =3D virISCSIScanTargetsInternal(portal, ifacename, + return virISCSIScanTargetsInternal(portal, ifacename, persist, ntargets, targets); - VIR_FREE(ifacename); - return ret; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714199451793.3540750939108; Wed, 8 Aug 2018 00:43:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AB69201FB; Wed, 8 Aug 2018 07:43:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C74DE1001938; Wed, 8 Aug 2018 07:43:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 682A04A469; Wed, 8 Aug 2018 07:43:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hFki005478 for ; Wed, 8 Aug 2018 03:43:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 56BA8261A5; Wed, 8 Aug 2018 07:43:15 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4CA53277D0 for ; Wed, 8 Aug 2018 07:43:13 +0000 (UTC) Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) (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 C647A5F737 for ; Wed, 8 Aug 2018 07:43:11 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id s17-v6so657397plp.7 for ; Wed, 08 Aug 2018 00:43:11 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=RQJxvoz8I58qeuFHOfFQMlhNrfoIhygBOtZn4p2VI20=; b=ulfMjKElWkj18FefFHMJLpOyW8I60KhITVTFmBuvLDRjp7hpMQKPa1kWDamcdKEDbY Ob2+egwYWgBEBCdoHpVTcXpDCkSGOd67IqtSpuL27BP40PPu/T1I9vhMNrbzvEzFKbfO 0An9wutGIqYdi/k5BeOi8Dgs4URf2R51M7nt/b1CXomUb4AAiYFIXnyCLWtNsPNwtJ4B GPwEBxPkjWiGlna4jfitMonWGFaNDWCmNRC34gsDAs0hnsCijGxVjrpYUAX7iiX3HLbD BJap2L4VcpFOKAFuigYbVshvpsnQlYwWNUR2cJC8eFZLJ+Xnagj+vWjfO/fA/adro2Cw QOmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=RQJxvoz8I58qeuFHOfFQMlhNrfoIhygBOtZn4p2VI20=; b=uOs0psfJARTT6c7JsYTaH2p5ZiZxM6tXm1KzLmNA626rBoAl3rSSyJUIyKByfan95j FZ21JUoiHBOaJVJyK5l6wSsejmwYqgm4FuCGn4RK2c3HXVj9+E3PA2gVa0dleRJI/Ajk W3c/aE+dPv7uOYiDfbwtiCmS5a5F2njkR33qzg34buzIp9DTLBXiv6pmA2fJtZ7hvxn4 UHANza0w0/rQVtinMJS8Dc+X3xRT5xCFTeGdXCZvtwf+q/KwGThEjcodrCq6aK+tZW90 lsENsKnExlhjGCOxZhZRGe5dviCK3Pe0SAMYTdlm+DFoHaxsdFZOymt9ApgnquS/01XU OlXg== X-Gm-Message-State: AOUpUlHBO4jWu2Y7zY2XolWVl7zRHxx0k/IhbiAC9UhBJJU8mBLfAy/Z t+CqO0/b+AMTF09fc3a9xiJU6u0x X-Google-Smtp-Source: AA+uWPzitOQDAqs1lr/wHTSG5jikCHhhui8/mUbNyQ++JpCYgJo51iGZtuA4yV1NLA2PPpn4EO2h2A== X-Received: by 2002:a17:902:740a:: with SMTP id g10-v6mr1527221pll.204.1533714190973; Wed, 08 Aug 2018 00:43:10 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:29 +0530 Message-Id: <1533501842-24503-3-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 08 Aug 2018 07:43:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 08 Aug 2018 07:43:11 +0000 (UTC) for IP:'209.85.160.65' DOMAIN:'mail-pl0-f65.google.com' HELO:'mail-pl0-f65.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.160.65 mail-pl0-f65.google.com 209.85.160.65 mail-pl0-f65.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 02/35] util: iscsi: use VIR_AUTOPTR for aggregate types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 08 Aug 2018 07:43:17 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/viriscsi.c | 100 +++++++++++++++++++-----------------------------= ---- 1 file changed, 36 insertions(+), 64 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 0c2d8bb..8c272b5 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -89,10 +89,10 @@ virISCSIGetSession(const char *devpath, .devpath =3D devpath, }; int exitstatus =3D 0; + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode= ", + "session", NULL); VIR_AUTOFREE(char *) error =3D NULL; =20 - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", - "session", NULL); virCommandSetErrorBuffer(cmd, &error); =20 if (virCommandRunRegex(cmd, @@ -101,15 +101,13 @@ virISCSIGetSession(const char *devpath, vars, virISCSIExtractSession, &cbdata, NULL, &exitstatus) < 0) - goto cleanup; + return cbdata.session; =20 if (cbdata.session =3D=3D NULL && !probe) virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find iscsiadm session: %s"), NULLSTR(error)); =20 - cleanup: - virCommandFree(cmd); return cbdata.session; } =20 @@ -125,8 +123,8 @@ virStorageBackendIQNFound(const char *initiatoriqn, { int ret =3D IQN_ERROR; char *line =3D NULL; - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, - "--mode", "iface", NULL); + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, + "--mode", "iface", = NULL); VIR_AUTOFREE(char *) outbuf =3D NULL; VIR_AUTOFREE(char *) iqn =3D NULL; =20 @@ -195,7 +193,6 @@ virStorageBackendIQNFound(const char *initiatoriqn, if (ret =3D=3D IQN_MISSING) VIR_DEBUG("Could not find interface with IQN '%s'", iqn); =20 - virCommandFree(cmd); return ret; =20 error: @@ -210,8 +207,8 @@ static int virStorageBackendCreateIfaceIQN(const char *initiatoriqn, char **ifacename) { - int ret =3D -1, exitstatus =3D -1; - virCommandPtr cmd =3D NULL; + int exitstatus =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) iface_name =3D NULL; VIR_AUTOFREE(char *) temp_ifacename =3D NULL; =20 @@ -236,7 +233,7 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to run command '%s' to create new iscsi i= nterface"), ISCSIADM); - goto cleanup; + return -1; } virCommandFree(cmd); =20 @@ -255,7 +252,7 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to run command '%s' to update iscsi inter= face with IQN '%s'"), ISCSIADM, initiatoriqn); - goto cleanup; + return -1; } =20 /* Check again to make sure the interface was created. */ @@ -263,7 +260,7 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, VIR_DEBUG("Failed to find interface '%s' with IQN '%s' " "after attempting to create it", &temp_ifacename[0], initiatoriqn); - goto cleanup; + return -1; } else { VIR_DEBUG("Interface '%s' with IQN '%s' was created successfully", iface_name, initiatoriqn); @@ -271,12 +268,7 @@ virStorageBackendCreateIfaceIQN(const char *initiatori= qn, =20 VIR_STEAL_PTR(*ifacename, iface_name); =20 - virCommandFree(cmd); return 0; - - cleanup: - virCommandFree(cmd); - return ret; } =20 =20 @@ -286,7 +278,6 @@ virISCSIConnection(const char *portal, const char *target, const char **extraargv) { - int ret =3D -1; const char *const baseargv[] =3D { ISCSIADM, "--mode", "node", @@ -294,7 +285,7 @@ virISCSIConnection(const char *portal, "--targetname", target, NULL }; - virCommandPtr cmd; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) ifacename =3D NULL; =20 cmd =3D virCommandNewArgs(baseargv); @@ -307,7 +298,7 @@ virISCSIConnection(const char *portal, break; case IQN_MISSING: if (virStorageBackendCreateIfaceIQN(initiatoriqn, &ifacename) = !=3D 0) - goto cleanup; + return -1; /* * iscsiadm doesn't let you send commands to the Interface IQN, * unless you've first issued a 'sendtargets' command to the @@ -318,25 +309,20 @@ virISCSIConnection(const char *portal, */ if (virISCSIScanTargetsInternal(portal, ifacename, true, NULL, NULL) < 0) - goto cleanup; + return -1; =20 break; case IQN_ERROR: default: - goto cleanup; + return -1; } virCommandAddArgList(cmd, "--interface", ifacename, NULL); } =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - virCommandFree(cmd); - - return ret; + return 0; } =20 =20 @@ -363,14 +349,12 @@ virISCSIConnectionLogout(const char *portal, int virISCSIRescanLUNs(const char *session) { - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, - "--mode", "session", - "-r", session, - "-R", - NULL); - int ret =3D virCommandRun(cmd, NULL); - virCommandFree(cmd); - return ret; + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, + "--mode", "session", + "-r", session, + "-R", + NULL); + return virCommandRun(cmd, NULL); } =20 =20 @@ -420,12 +404,11 @@ virISCSIScanTargetsInternal(const char *portal, int vars[] =3D { 2 }; struct virISCSITargetList list; size_t i; - int ret =3D -1; - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, - "--mode", "discovery", - "--type", "sendtargets", - "--portal", portal, - NULL); + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, + "--mode", "discover= y", + "--type", "sendtarg= ets", + "--portal", portal, + NULL); =20 if (!persist) { virCommandAddArgList(cmd, @@ -447,7 +430,7 @@ virISCSIScanTargetsInternal(const char *portal, vars, virISCSIGetTargets, &list, NULL, NULL) < 0) - goto cleanup; + return -1; =20 if (ntargetsret && targetsret) { *ntargetsret =3D list.ntargets; @@ -458,10 +441,7 @@ virISCSIScanTargetsInternal(const char *portal, VIR_FREE(list.targets); } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -539,9 +519,8 @@ int virISCSINodeNew(const char *portal, const char *target) { - virCommandPtr cmd =3D NULL; int status; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "node", @@ -554,20 +533,17 @@ virISCSINodeNew(const char *portal, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed new node mode for target '%s'"), target); - goto cleanup; + return -1; } =20 if (status !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s failed new mode for target '%s' with status '= %d'"), ISCSIADM, target, status); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -577,9 +553,8 @@ virISCSINodeUpdate(const char *portal, const char *name, const char *value) { - virCommandPtr cmd =3D NULL; int status; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "node", @@ -595,11 +570,8 @@ virISCSINodeUpdate(const char *portal, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to update '%s' of node mode for target '%= s'"), name, target); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714206286472.3031661761639; Wed, 8 Aug 2018 00:43:26 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1A1FC307D853; Wed, 8 Aug 2018 07:43:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D63E51001F45; Wed, 8 Aug 2018 07:43:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 878504A46E; Wed, 8 Aug 2018 07:43:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hKba005488 for ; Wed, 8 Aug 2018 03:43:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 92BC6308BDB2; Wed, 8 Aug 2018 07:43:20 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 850AB308BDA4 for ; Wed, 8 Aug 2018 07:43:17 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (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 6A0D012C06 for ; Wed, 8 Aug 2018 07:43:16 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id r1-v6so676621pgp.11 for ; Wed, 08 Aug 2018 00:43:16 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=Rg7cQskX7OhaAp/fQcvaPAyBYmWAzulInACY3dQEalg=; b=TZrXxo4S5cCXJ4ihk04ie/GiFZn6W55roM9LCsdov/g/kAydmhkrdDYBuEvYaB2MZm kdckp6cTxyIBGCgWvfSk6ZkVOQ6S0CuIev6mU4WUj/fwoAbfFhL60Rasqn2KquJ89rRG 8Ow1y8ZVQ1pcsctVpmTuWxXxGgAf6L+8fCPKOLh2GFkcLTjWnnQJMwF6gt6jA8t7w34t 6r74o/g05cyy7koJkZPqvOZfftdfLWzloJ1/fj00p6COSHN9AKxEl9MOop40HK5JOrlK 1pDkDfrYb+eFt6NfgyCgdEtWtE5O7/GVXGyhvBAfE/UFos1+l0g9IWuJg5A9NqVJ9814 UcUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Rg7cQskX7OhaAp/fQcvaPAyBYmWAzulInACY3dQEalg=; b=qG5lEm2ux4WhYxCpU8ZVuHCLqQrfMIzcFbimCf2iqP63AnvJ05aCcBSo8w3QcYkk91 ZZeyX2D8E0RivaQ5TCnhu/TwuFMjRMqOua6n556ChnBGURv1LHptzfSxEqGG1NXX29ml g6Jewdn2Ph4/QzLn202Ac2l+tvmVxmSApD3Q+42QNiucLravmyM27ymfAN+z0Gu9ykil VtMNQeUiQmPHOHVjGd6uzhQL3Mmm/9O57qFU3z0IUHFC4WKr7/Oblp5K1w9sBL+Y+DUH GETUwGdYw3mVPaay13BzBifb9IGO0se1luQ9wiOz1JOlj3LaMTJsWUiroDZPPAPAjcdx +OIQ== X-Gm-Message-State: AOUpUlEdvnZnOHv51va4e3SkZjA10DxpUdjO3F8BYEBDvDJ6QfqueCaZ wKnIZ+kVfKxml0oVaGzXyACj63hV X-Google-Smtp-Source: AA+uWPxYzRRoYXU3n3tRSte3Mebojd+TaG0nEqhOAyowXQQaN8jkJQU9CJBzAVUbgazgQAKbA7EE1Q== X-Received: by 2002:a62:4f5b:: with SMTP id d88-v6mr1704890pfb.225.1533714195675; Wed, 08 Aug 2018 00:43:15 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:30 +0530 Message-Id: <1533501842-24503-4-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:43:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:43:16 +0000 (UTC) for IP:'209.85.215.196' DOMAIN:'mail-pg1-f196.google.com' HELO:'mail-pg1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.215.196 mail-pg1-f196.google.com 209.85.215.196 mail-pg1-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 03/35] util: netlink: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 08 Aug 2018 07:43:24 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. This commit also typedefs virNlMsg to struct nl_msg type for use with the cleanup macros. When pointers to virNlMsg and virNetlinkHandle types are declared using VIR_AUTOPTR, the functions nlmsg_free and virNetlinkFree, respectively, will be run automatically on them when they go out of scope. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetlink.c | 3 ++- src/util/virnetlink.h | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index fa1ba3e..1c1eac7 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -38,7 +38,6 @@ #include "virnetlink.h" #include "virnetdev.h" #include "virlog.h" -#include "viralloc.h" #include "virthread.h" #include "virmacaddr.h" #include "virerror.h" @@ -72,6 +71,8 @@ typedef struct nl_handle virNetlinkHandle; typedef struct nl_sock virNetlinkHandle; # endif =20 +VIR_DEFINE_AUTOPTR_FUNC(virNetlinkHandle, virNetlinkFree) + typedef struct _virNetlinkEventSrvPrivate virNetlinkEventSrvPrivate; typedef virNetlinkEventSrvPrivate *virNetlinkEventSrvPrivatePtr; struct _virNetlinkEventSrvPrivate { diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h index 2a9de0a..647f589 100644 --- a/src/util/virnetlink.h +++ b/src/util/virnetlink.h @@ -44,6 +44,9 @@ struct nlmsghdr; =20 # endif /* __linux__ */ =20 +typedef struct nl_msg virNlMsg; +typedef virNlMsg *virNlMsgPtr; + int virNetlinkStartup(void); void virNetlinkShutdown(void); =20 @@ -123,4 +126,6 @@ int virNetlinkEventAddClient(virNetlinkEventHandleCallb= ack handleCB, int virNetlinkEventRemoveClient(int watch, const virMacAddr *macaddr, unsigned int protocol); =20 +VIR_DEFINE_AUTOPTR_FUNC(virNlMsg, nlmsg_free) + #endif /* __VIR_NETLINK_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714208934219.53832649139838; Wed, 8 Aug 2018 00:43:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C001B30E685C; Wed, 8 Aug 2018 07:43:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8A32B2015660; Wed, 8 Aug 2018 07:43:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 40B2641091; Wed, 8 Aug 2018 07:43:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hMtL005502 for ; Wed, 8 Aug 2018 03:43:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id D8486608F2; Wed, 8 Aug 2018 07:43:22 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CEC5A608E0 for ; Wed, 8 Aug 2018 07:43:19 +0000 (UTC) Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 5A53030832C8 for ; Wed, 8 Aug 2018 07:43:18 +0000 (UTC) Received: by mail-pg1-f172.google.com with SMTP id y5-v6so699996pgv.1 for ; Wed, 08 Aug 2018 00:43:18 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=g3qTCEPoMjKM1Ttz9tE2zRDr+cfSzvxDsgGJx0WN6KA=; b=us3oydJc4uiGwEGGGKKNAj9mLKlK4GSVA9eplR06dqclatUfWByb3nFNJkeADYlRNg l+PbwvZuXeRpq3ZSq51i42TaYgrkkerPJ2uQjiIJ9TbWe/RoBCdY/ip4EF+ejIk5/16T YW3YxJniy0wdb9crZlbgeeLy6kIYes8I+a7Jxs3eDQ9Ipg3SfU/rezYd1Mk7LVtFfqKM oV3grrq3AGMdZW5ylG03t+o7cL8LvberJroYW9ywCx77rqRZedyJrWDZjD5qT/PCPt+d vMoOtjEd7trX/qddUorxlIBHKWRejYrH3BDwRU1YwrsCseiK5ABKkMEOdEvK74K1di6A q9Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=g3qTCEPoMjKM1Ttz9tE2zRDr+cfSzvxDsgGJx0WN6KA=; b=IDDHw45wkJPfa5hKR2cGGIS3zXsWfKds3OlLEzAfo8bfXspjMN3fb4QH0UKiqVJtQK c7JuOqHC/TahSFCe/940VhSROBnMlRujBIIRY2v0M1xaPewQ8omI4TJdHl7LSVH8txGP LO7IrGnz/RP01R4GJTWFGUSwxF2Wy6UARsxayzNlANxYQkvpHffWKZoZ6N/xAy3BnmZ/ ty5P1Tgou23jn1lDv4kNcKiqqtyuU0NJrUqR7rZ+Zn7g8YqC8XB35crnsVTWNABv0FBk wGGpHfLf/0D0MpduIo33kBGCS8CSZDWY07NmKkMAmlplbcHv0AFv8SKEmEnp3AAI/0q4 YIpA== X-Gm-Message-State: AOUpUlHKKT0hjGRr6DQNwe9j4thF2kuiA/boLqxBPEjWd+ev8op++fXC pHt3vk9dw9q/Az3lJQaENEXY+RTF X-Google-Smtp-Source: AA+uWPxvxKJIEx5RMfWdzUAn+2ZI2ATyvqrm11W56wjNvoPZMHh9qiBkPWjFfGYUEakDzIGoOq735A== X-Received: by 2002:a63:41c6:: with SMTP id o189-v6mr1478914pga.323.1533714197647; Wed, 08 Aug 2018 00:43:17 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:31 +0530 Message-Id: <1533501842-24503-5-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:43:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:43:18 +0000 (UTC) for IP:'209.85.215.172' DOMAIN:'mail-pg1-f172.google.com' HELO:'mail-pg1-f172.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.215.172 mail-pg1-f172.google.com 209.85.215.172 mail-pg1-f172.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 04/35] util: netlink: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 08 Aug 2018 07:43:27 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetlink.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 1c1eac7..aa3a86d 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -346,7 +346,6 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, int ret =3D -1; bool end =3D false; int len =3D 0; - struct nlmsghdr *resp =3D NULL; struct nlmsghdr *msg =3D NULL; =20 struct sockaddr_nl nladdr =3D { @@ -361,6 +360,8 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, goto cleanup; =20 while (!end) { + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + len =3D nl_recv(nlhandle, &nladdr, (unsigned char **)&resp, NULL); VIR_WARNINGS_NO_CAST_ALIGN for (msg =3D resp; NLMSG_OK(msg, len); msg =3D NLMSG_NEXT(msg, len= )) { @@ -374,13 +375,11 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, if (callback(msg, opaque) < 0) goto cleanup; } - VIR_FREE(resp); } =20 ret =3D 0; =20 cleanup: - VIR_FREE(resp); virNetlinkFree(nlhandle); return ret; } @@ -410,7 +409,6 @@ virNetlinkDumpLink(const char *ifname, int ifindex, uint32_t src_pid, uint32_t dst_pid) { int rc =3D -1; - struct nlmsghdr *resp =3D NULL; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC, @@ -418,6 +416,9 @@ virNetlinkDumpLink(const char *ifname, int ifindex, }; unsigned int recvbuflen; struct nl_msg *nl_msg; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + + *nlData =3D NULL; =20 if (ifname && ifindex <=3D 0 && virNetDevGetIndex(ifname, &ifindex) < = 0) return -1; @@ -485,12 +486,12 @@ virNetlinkDumpLink(const char *ifname, int ifindex, default: goto malformed_resp; } + + VIR_STEAL_PTR(*nlData, resp); rc =3D 0; + cleanup: nlmsg_free(nl_msg); - if (rc < 0) - VIR_FREE(resp); - *nlData =3D resp; return rc; =20 malformed_resp: @@ -524,11 +525,11 @@ int virNetlinkDelLink(const char *ifname, virNetlinkDelLinkFallback fallback) { int rc =3D -1; - struct nlmsghdr *resp =3D NULL; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC }; unsigned int recvbuflen; struct nl_msg *nl_msg; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 nl_msg =3D nlmsg_alloc_simple(RTM_DELLINK, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL); @@ -579,7 +580,6 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLink= Fallback fallback) rc =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -612,13 +612,15 @@ int virNetlinkGetNeighbor(void **nlData, uint32_t src_pid, uint32_t dst_pid) { int rc =3D -1; - struct nlmsghdr *resp =3D NULL; struct nlmsgerr *err; struct ndmsg ndinfo =3D { .ndm_family =3D AF_UNSPEC, }; unsigned int recvbuflen; struct nl_msg *nl_msg; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + + *nlData =3D NULL; =20 nl_msg =3D nlmsg_alloc_simple(RTM_GETNEIGH, NLM_F_DUMP | NLM_F_REQUEST= ); if (!nl_msg) { @@ -656,13 +658,12 @@ virNetlinkGetNeighbor(void **nlData, uint32_t src_pid= , uint32_t dst_pid) default: goto malformed_resp; } + + VIR_STEAL_PTR(*nlData, resp); rc =3D recvbuflen; =20 cleanup: nlmsg_free(nl_msg); - if (rc < 0) - VIR_FREE(resp); - *nlData =3D resp; return rc; =20 malformed_resp: @@ -768,12 +769,12 @@ virNetlinkEventCallback(int watch, void *opaque) { virNetlinkEventSrvPrivatePtr srv =3D opaque; - struct nlmsghdr *msg; struct sockaddr_nl peer; struct ucred *creds =3D NULL; size_t i; int length; bool handled =3D false; + VIR_AUTOFREE(struct nlmsghdr *) msg =3D NULL; =20 length =3D nl_recv(srv->netlinknh, &peer, (unsigned char **)&msg, &creds); @@ -803,7 +804,7 @@ virNetlinkEventCallback(int watch, =20 if (!handled) VIR_DEBUG("event not handled."); - VIR_FREE(msg); + virNetlinkEventServerUnlock(srv); } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153371421007340.61538177862565; Wed, 8 Aug 2018 00:43:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D26FF821CB; Wed, 8 Aug 2018 07:43:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7710B65325; Wed, 8 Aug 2018 07:43:27 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2638118037F0; Wed, 8 Aug 2018 07:43:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hNP1005515 for ; Wed, 8 Aug 2018 03:43:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id ADE205D9CA; Wed, 8 Aug 2018 07:43:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A3C3B5D9C9 for ; Wed, 8 Aug 2018 07:43:21 +0000 (UTC) Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (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 88061C049D64 for ; Wed, 8 Aug 2018 07:43:20 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id w10-v6so697898pgv.2 for ; Wed, 08 Aug 2018 00:43:20 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=b2yc2xPot4OY67CVnw41dxTNYUHd2Tb9ZYPAOwxnb3c=; b=S4dn52BUVB4M/YpZzl4k42xjmoiUZa14Dg5LiNydneDwB36coIn4rO89jrKx/HHugE D10tEMR7WZV1nCoY8pxgLbjYIdkAUuTHPMaF/wKSgI5A6hOw2nCXD5FXxNicYVrYFU6R RKSzkp82XwRmnfX7QtQKYr51htbu7fbfgFhpUBtjCIe7J6y2bQfnP/7/0yosvaIX5tQd PjuT8rXgNv+mom3YaSPh377ajf7ftqNrAdEKj9qA5pxSzE1JGPLITIBnXUb8HnAJc+/v hCAqqYnl3Ds1FzjbHUmHZ6UPiMSHK2zCyqrwlQlnfrFSUrVnyyuAto9DvvXjZA1bP4d7 wUfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=b2yc2xPot4OY67CVnw41dxTNYUHd2Tb9ZYPAOwxnb3c=; b=E/uMnk4oAbOOlTKNDyxlBdRLhWsPvEoM9cszNCIH4UL6HEPjTYrt5+vc4nZNfYRy6A BP3io/ckMnOfBfwDlghgwbwvyLMnvKoFnbYv8hP+6Q83QEuf7RYQ5CoLI9W695Kb7oBM spGiUQ8UqEQQcSFRwdKZxrYJ6WJzSq4A/ZwJmypApf7fL8HviVFljyJ3K+wA3WCTPQpB lHOv2eKPZPRZQ3zIomQq4CxZuTf+26mW/e7A9Ph1Zy6lKlb9ANheU+/gz3jv3jsbeNzt 7M5ScxooBGuGrOcNHAVRWWpiXPyDAqWfmhtuHCyLwRO+5Ndma/2yjzSLsHWT6XrvDkqN YO3Q== X-Gm-Message-State: AOUpUlHUIWbkIy+LoytZYECoAbnCQ8NBNxxQ+cuHkBBXi9e8s9qL/lV3 FsMudvMUj8mHk9CcCWWzmxPt2KLP X-Google-Smtp-Source: AA+uWPzMpFb3+I0kXMUWfx2eWh3vcOVaULJQMyBxNlmm/IkOpu4EVTKBxgAprulAhVUqJFggTuBvGA== X-Received: by 2002:a63:f713:: with SMTP id x19-v6mr1451641pgh.233.1533714199753; Wed, 08 Aug 2018 00:43:19 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:32 +0530 Message-Id: <1533501842-24503-6-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 08 Aug 2018 07:43:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 08 Aug 2018 07:43:20 +0000 (UTC) for IP:'209.85.215.175' DOMAIN:'mail-pg1-f175.google.com' HELO:'mail-pg1-f175.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.215.175 mail-pg1-f175.google.com 209.85.215.175 mail-pg1-f175.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 05/35] util: netlink: use VIR_AUTOPTR for aggregate types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 08 Aug 2018 07:43:28 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetlink.c | 88 +++++++++++++++++++----------------------------= ---- 1 file changed, 33 insertions(+), 55 deletions(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index aa3a86d..66e80e2 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -297,15 +297,16 @@ int virNetlinkCommand(struct nl_msg *nl_msg, uint32_t src_pid, uint32_t dst_pid, unsigned int protocol, unsigned int groups) { - int ret =3D -1; struct sockaddr_nl nladdr =3D { .nl_family =3D AF_NETLINK, .nl_pid =3D dst_pid, .nl_groups =3D 0, }; struct pollfd fds[1]; - virNetlinkHandle *nlhandle =3D NULL; int len =3D 0; + VIR_AUTOPTR(virNetlinkHandle) nlhandle =3D NULL; + + *respbuflen =3D 0; =20 memset(fds, 0, sizeof(fds)); =20 @@ -324,16 +325,12 @@ int virNetlinkCommand(struct nl_msg *nl_msg, goto cleanup; } =20 - ret =3D 0; *respbuflen =3D len; - cleanup: - if (ret < 0) { - *resp =3D NULL; - *respbuflen =3D 0; - } + return 0; =20 - virNetlinkFree(nlhandle); - return ret; + cleanup: + *resp =3D NULL; + return -1; } =20 int @@ -343,7 +340,6 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, unsigned int protocol, unsigned int groups, void *opaque) { - int ret =3D -1; bool end =3D false; int len =3D 0; struct nlmsghdr *msg =3D NULL; @@ -353,11 +349,11 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, .nl_pid =3D dst_pid, .nl_groups =3D 0, }; - virNetlinkHandle *nlhandle =3D NULL; + VIR_AUTOPTR(virNetlinkHandle) nlhandle =3D NULL; =20 if (!(nlhandle =3D virNetlinkSendRequest(nl_msg, src_pid, nladdr, protocol, groups))) - goto cleanup; + return -1; =20 while (!end) { VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; @@ -370,18 +366,14 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, end =3D true; =20 if (virNetlinkGetErrorCode(msg, len) < 0) - goto cleanup; + return -1; =20 if (callback(msg, opaque) < 0) - goto cleanup; + return -1; } } =20 - ret =3D 0; - - cleanup: - virNetlinkFree(nlhandle); - return ret; + return 0; } =20 /** @@ -415,7 +407,7 @@ virNetlinkDumpLink(const char *ifname, int ifindex, .ifi_index =3D ifindex }; unsigned int recvbuflen; - struct nl_msg *nl_msg; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 *nlData =3D NULL; @@ -456,7 +448,7 @@ virNetlinkDumpLink(const char *ifname, int ifindex, =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, src_pid, dst_pid, NETLINK_ROUTE, 0) < 0) - goto cleanup; + return -1; =20 if (recvbuflen < NLMSG_LENGTH(0) || resp =3D=3D NULL) goto malformed_resp; @@ -471,7 +463,7 @@ virNetlinkDumpLink(const char *ifname, int ifindex, virReportSystemError(-err->error, _("error dumping %s (%d) interface"), ifname, ifindex); - goto cleanup; + return -1; } break; =20 @@ -488,21 +480,17 @@ virNetlinkDumpLink(const char *ifname, int ifindex, } =20 VIR_STEAL_PTR(*nlData, resp); - rc =3D 0; - - cleanup: - nlmsg_free(nl_msg); - return rc; + return 0; =20 malformed_resp: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed netlink response message")); - goto cleanup; + return rc; =20 buffer_too_small: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return rc; } =20 =20 @@ -524,11 +512,10 @@ virNetlinkDumpLink(const char *ifname, int ifindex, int virNetlinkDelLink(const char *ifname, virNetlinkDelLinkFallback fallback) { - int rc =3D -1; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC }; unsigned int recvbuflen; - struct nl_msg *nl_msg; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 nl_msg =3D nlmsg_alloc_simple(RTM_DELLINK, @@ -546,7 +533,7 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLink= Fallback fallback) =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) { - goto cleanup; + return -1; } =20 if (recvbuflen < NLMSG_LENGTH(0) || resp =3D=3D NULL) @@ -558,15 +545,14 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLi= nkFallback fallback) if (resp->nlmsg_len < NLMSG_LENGTH(sizeof(*err))) goto malformed_resp; =20 - if (-err->error =3D=3D EOPNOTSUPP && fallback) { - rc =3D fallback(ifname); - goto cleanup; - } + if (-err->error =3D=3D EOPNOTSUPP && fallback) + return fallback(ifname); + if (err->error) { virReportSystemError(-err->error, _("error destroying network device %s"), ifname); - goto cleanup; + return -1; } break; =20 @@ -577,20 +563,17 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLi= nkFallback fallback) goto malformed_resp; } =20 - rc =3D 0; - cleanup: - nlmsg_free(nl_msg); - return rc; + return 0; =20 malformed_resp: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed netlink response message")); - goto cleanup; + return -1; =20 buffer_too_small: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 /** @@ -611,13 +594,12 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLi= nkFallback fallback) int virNetlinkGetNeighbor(void **nlData, uint32_t src_pid, uint32_t dst_pid) { - int rc =3D -1; struct nlmsgerr *err; struct ndmsg ndinfo =3D { .ndm_family =3D AF_UNSPEC, }; unsigned int recvbuflen; - struct nl_msg *nl_msg; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 *nlData =3D NULL; @@ -634,7 +616,7 @@ virNetlinkGetNeighbor(void **nlData, uint32_t src_pid, = uint32_t dst_pid) =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, src_pid, dst_pid, NETLINK_ROUTE, 0) < 0) - goto cleanup; + return -1; =20 if (recvbuflen < NLMSG_LENGTH(0) || resp =3D=3D NULL) goto malformed_resp; @@ -648,7 +630,7 @@ virNetlinkGetNeighbor(void **nlData, uint32_t src_pid, = uint32_t dst_pid) if (err->error) { virReportSystemError(-err->error, "%s", _("error dumping")); - goto cleanup; + return -1; } break; =20 @@ -660,21 +642,17 @@ virNetlinkGetNeighbor(void **nlData, uint32_t src_pid= , uint32_t dst_pid) } =20 VIR_STEAL_PTR(*nlData, resp); - rc =3D recvbuflen; - - cleanup: - nlmsg_free(nl_msg); - return rc; + return recvbuflen; =20 malformed_resp: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed netlink response message")); - goto cleanup; + return -1; =20 buffer_too_small: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 int --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15337142129191009.6956320170817; Wed, 8 Aug 2018 00:43:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF747308402D; Wed, 8 Aug 2018 07:43:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3B7765954; Wed, 8 Aug 2018 07:43:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4F8853FC9D; Wed, 8 Aug 2018 07:43:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hNuM005509 for ; Wed, 8 Aug 2018 03:43:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 599D5608F2; Wed, 8 Aug 2018 07:43:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 51593608E0 for ; Wed, 8 Aug 2018 07:43:23 +0000 (UTC) Received: from mail-pl0-f49.google.com (mail-pl0-f49.google.com [209.85.160.49]) (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 58551307D853 for ; Wed, 8 Aug 2018 07:43:22 +0000 (UTC) Received: by mail-pl0-f49.google.com with SMTP id ba4-v6so647751plb.11 for ; Wed, 08 Aug 2018 00:43:22 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=3rBn7F42VIgSEAsQ5noaxMLwsf2x6yeWQZ8PK6z/51o=; b=CBG7X8WR6T5+Gm/Z8ZzUT4uRcSge3dRARKl7sgJI3hdSOcyRz3T2hnP7/PgoAAalQA yR0e/0mirY9nNDM70vLL9huVQwMQVQKHBzCSUmBZLDBnhE3kBTACMErqm83AGzuIzpaW 551Jg2hgOwdeVjCgrZJ1WfeNEwk3cNxYqCk2v7WOeRIJec0rH2bz/GD61Se/o9EP0/5V 4DNhQInSUleztYDMt+lduHUcNNFPW85UH99hAZ4tH5dSyjXf3V/EJxpfhdDLkn2z00T8 NITtjQ71oCNr4F8jAGKaKyja8KDHSBA7O5ZvapaNZylaP4r9VTHXJo946NHo5nMeiAhW FJQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=3rBn7F42VIgSEAsQ5noaxMLwsf2x6yeWQZ8PK6z/51o=; b=h54lqnjnoFOu4sUjj5THBolaiBJZ88eLz/UreZit3GipTWv7Ms6KYprOjX5mCAXFDZ eurBfrggVS3yggZftQxMq6ncGKkmWMMEx5PpJtiVHCTketFfTThNckvtmJ7eGGxYMh5S xr5dkDmUqy6pCIMHN2nCURruYTCwSKIbpl+7QQEph8vRQAPIlA4YDXbszpyWIUnDXoxN QZLqtOumNqZqEv7x76lP1uzDQv17LqbbOZHyhfbuSpa1FoZ1crYapGbPVIbpIvkB3gY1 TfTzgyCDu2Y2M8TqN9+XWZvVnlKC8FNZK2rRaL3v7SfVTKfFPluop+EGd3ZhV6+P+XgN 63kA== X-Gm-Message-State: AOUpUlER4BTNVv9p/GDZsnkuK+sOzeTU5UXdatPCL3pNp6C5Ww/k18Iq Yg68XHNtKtmc+MJvnkcP5PChmyFU X-Google-Smtp-Source: AA+uWPwZ4WbNqHxPfJDeAUETVyb7c+KPY2BsZMxmOXXernJYGCisA8wFegZY//g3tKMOHjlsJk6XFQ== X-Received: by 2002:a17:902:24c7:: with SMTP id l7-v6mr1517194plg.170.1533714201593; Wed, 08 Aug 2018 00:43:21 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:33 +0530 Message-Id: <1533501842-24503-7-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 08 Aug 2018 07:43:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 08 Aug 2018 07:43:22 +0000 (UTC) for IP:'209.85.160.49' DOMAIN:'mail-pl0-f49.google.com' HELO:'mail-pl0-f49.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.160.49 mail-pl0-f49.google.com 209.85.160.49 mail-pl0-f49.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 06/35] util: netdevbridge: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 08 Aug 2018 07:43:31 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevbridge.c | 46 ++++++++++++++++--------------------------= ---- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index e46ac35..fe3697b 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -126,8 +126,7 @@ static int virNetDevBridgeSet(const char *brname, int fd, /* control socket */ struct ifreq *ifr) /* pre-filled bridge= name */ { - char *path =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname= ) < 0) return -1; @@ -138,7 +137,7 @@ static int virNetDevBridgeSet(const char *brname, if (virFileWriteStr(path, valuestr, 0) < 0) { virReportSystemError(errno, _("Unable to set bridge %s %s"), brname, = paramname); - goto cleanup; + return -1; } } else { unsigned long paramid; @@ -149,21 +148,18 @@ static int virNetDevBridgeSet(const char *brname, } else { virReportSystemError(EINVAL, _("Unable to set bridge %s %s"), brname, = paramname); - goto cleanup; + return -1; } unsigned long args[] =3D { paramid, value, 0, 0 }; ifr->ifr_data =3D (char*)&args; if (ioctl(fd, SIOCDEVPRIVATE, ifr) < 0) { virReportSystemError(errno, _("Unable to set bridge %s %s"), brname, = paramname); - goto cleanup; + return -1; } } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - return ret; + return 0; } =20 =20 @@ -171,16 +167,17 @@ static int virNetDevBridgeGet(const char *brname, const char *paramname, /* sysfs param name = */ unsigned long *value) /* current value */ { - char *path =3D NULL; int ret =3D -1; int fd =3D -1; struct ifreq ifr; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname= ) < 0) return -1; =20 if (virFileExists(path)) { - char *valuestr; + VIR_AUTOFREE(char *) valuestr =3D NULL; + if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) < 0) goto cleanup; @@ -189,10 +186,8 @@ static int virNetDevBridgeGet(const char *brname, virReportSystemError(EINVAL, _("Unable to get bridge %s %s"), brname, paramname); - VIR_FREE(valuestr); goto cleanup; } - VIR_FREE(valuestr); } else { struct __bridge_info info; unsigned long args[] =3D { BRCTL_GET_BRIDGE_INFO, (unsigned long)&= info, 0, 0 }; @@ -221,7 +216,6 @@ static int virNetDevBridgeGet(const char *brname, ret =3D 0; cleanup: VIR_FORCE_CLOSE(fd); - VIR_FREE(path); return ret; } #endif /* __linux__ */ @@ -233,9 +227,9 @@ virNetDevBridgePortSet(const char *brname, const char *paramname, unsigned long value) { - char *path =3D NULL; char valuestr[INT_BUFSIZE_BOUND(value)]; int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; =20 snprintf(valuestr, sizeof(valuestr), "%lu", value); =20 @@ -254,7 +248,6 @@ virNetDevBridgePortSet(const char *brname, brname, ifname, paramname, valuestr); } =20 - VIR_FREE(path); return ret; } =20 @@ -265,29 +258,24 @@ virNetDevBridgePortGet(const char *brname, const char *paramname, unsigned long *value) { - char *path =3D NULL; - char *valuestr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) valuestr =3D NULL; =20 if (virAsprintf(&path, SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname, paramname) < 0) return -1; =20 if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) = < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ul(valuestr, NULL, 10, value) < 0) { virReportSystemError(EINVAL, _("Unable to get bridge %s port %s %s"), brname, ifname, paramname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(valuestr); - return ret; + return 0; } =20 =20 @@ -430,12 +418,12 @@ virNetDevBridgeCreate(const char *brname) /* use a netlink RTM_NEWLINK message to create the bridge */ const char *type =3D "bridge"; int rc =3D -1; - struct nlmsghdr *resp =3D NULL; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC }; unsigned int recvbuflen; struct nl_msg *nl_msg; struct nlattr *linkinfo; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 nl_msg =3D nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL); @@ -495,7 +483,6 @@ virNetDevBridgeCreate(const char *brname) rc =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -1069,11 +1056,11 @@ virNetDevBridgeFDBAddDel(const virMacAddr *mac, con= st char *ifname, unsigned int flags, bool isAdd) { int ret =3D -1; - struct nlmsghdr *resp =3D NULL; struct nlmsgerr *err; unsigned int recvbuflen; struct nl_msg *nl_msg; struct ndmsg ndm =3D { .ndm_family =3D PF_BRIDGE, .ndm_state =3D NUD_N= OARP }; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (virNetDevGetIndex(ifname, &ndm.ndm_ifindex) < 0) return -1; @@ -1142,7 +1129,6 @@ virNetDevBridgeFDBAddDel(const virMacAddr *mac, const= char *ifname, ret =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return ret; =20 malformed_resp: --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714213917794.4518456791586; Wed, 8 Aug 2018 00:43:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D6C1550D6; Wed, 8 Aug 2018 07:43:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6AD6FCBA38; Wed, 8 Aug 2018 07:43:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1FD3B3F8F1; Wed, 8 Aug 2018 07:43:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hSsr005546 for ; Wed, 8 Aug 2018 03:43:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id E937F17D2B; Wed, 8 Aug 2018 07:43:28 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A8DC217D3C for ; Wed, 8 Aug 2018 07:43:25 +0000 (UTC) Received: from mail-pl0-f49.google.com (mail-pl0-f49.google.com [209.85.160.49]) (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 55614821C3 for ; Wed, 8 Aug 2018 07:43:24 +0000 (UTC) Received: by mail-pl0-f49.google.com with SMTP id s17-v6so657658plp.7 for ; Wed, 08 Aug 2018 00:43:24 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=velbeesQ6GSKKAMIFvxPnSBhuabGcrN7cK8rGDYQSyg=; b=a2L/HfUmQlrwW0ejo7LAZsz1jHdNJIfq0kk8PNFms0z769Pas2v8ZOq62ZDm0y36Rt DMcInn0J0iujl6YLdnkfmhg3fTy9OvUv+Wl1lizl+elfYHu96KIuyR2B6ckdHxuFZyqf kETpjeYUuBtvO9opzBH/hjfDWcIpmnUzT3BKCJ9knxb7MKIn4jxnSvlOXn43nWO0hid1 51w17r4atOQOfg5ZHinT+46hky9ySJiPvbNEyKAvsRTu9jRuYpI5t/XrGXFH10El9KGV oMMcDOEUTFlwKCFTEneJg75gwjy/dt8p4N65Abt2A9V+aWpTKFZz4Gv6FsH+Xvrr7ey8 73iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=velbeesQ6GSKKAMIFvxPnSBhuabGcrN7cK8rGDYQSyg=; b=sec0467praX9mano1LbgmbKsbiVfFSkYJuEWZb5KsUBD/cQtKiSdPRy5jL+kpNn3ZJ 7Uw56cVmnF4CHDGisdKSpM3ZNk/vrfmfEbfDXl5pJDW/tyEKI+GKmEWxaSWwQxtHUfnL ZLBYWNrv2o7+hBWNC5yUFksbzTwQv22fRuYIQuLXS2BxJFVX+WF7pLPEqOsZTCnK5yGM OjFbP4t+ZaBwbvX1asalbXPhP4aFXy7l53pBoYhBZkD5rsTrk3+KSTqwXIDzAcltqBG/ iR1igRPuwNs6VTeI8Y0xgURfJF455BYCZ0vIiR3ck/Zfc9W7zNJUREgHM65hJwrU6PZp BQOQ== X-Gm-Message-State: AOUpUlGnB27s+xdwtoyq7Vsv3CNfFc2yBxsf1cetwcL9pddROlW7MZaY byhkH8XQZ4lmdNnbXdfC82tSd7UB X-Google-Smtp-Source: AA+uWPw56RDtxQePV2itQ8iw5VcssWOeO+8mgkCTTDqZnSwhGB/gCRUnPq/sXLt40K8IhSiim+DENA== X-Received: by 2002:a17:902:48c8:: with SMTP id u8-v6mr1530194plh.152.1533714203547; Wed, 08 Aug 2018 00:43:23 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:34 +0530 Message-Id: <1533501842-24503-8-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 08 Aug 2018 07:43:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 08 Aug 2018 07:43:24 +0000 (UTC) for IP:'209.85.160.49' DOMAIN:'mail-pl0-f49.google.com' HELO:'mail-pl0-f49.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.160.49 mail-pl0-f49.google.com 209.85.160.49 mail-pl0-f49.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 07/35] util: netdevbridge: use VIR_AUTOPTR for aggregate types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 08 Aug 2018 07:43:32 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevbridge.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index fe3697b..089da78 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -417,12 +417,11 @@ virNetDevBridgeCreate(const char *brname) { /* use a netlink RTM_NEWLINK message to create the bridge */ const char *type =3D "bridge"; - int rc =3D -1; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC }; unsigned int recvbuflen; - struct nl_msg *nl_msg; struct nlattr *linkinfo; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 nl_msg =3D nlmsg_alloc_simple(RTM_NEWLINK, @@ -444,7 +443,7 @@ virNetDevBridgeCreate(const char *brname) =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) { - goto cleanup; + return -1; } =20 if (recvbuflen < NLMSG_LENGTH(0) || resp =3D=3D NULL) @@ -462,15 +461,14 @@ virNetDevBridgeCreate(const char *brname) /* fallback to ioctl if netlink doesn't support creating * bridges */ - rc =3D virNetDevBridgeCreateWithIoctl(brname); - goto cleanup; + return virNetDevBridgeCreateWithIoctl(brname); } # endif =20 virReportSystemError(-err->error, _("error creating bridge interface %s"), brname); - goto cleanup; + return -1; } break; =20 @@ -480,19 +478,16 @@ virNetDevBridgeCreate(const char *brname) goto malformed_resp; } =20 - rc =3D 0; - cleanup: - nlmsg_free(nl_msg); - return rc; + return 0; =20 malformed_resp: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed netlink response message")); - goto cleanup; + return -1; buffer_too_small: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 =20 @@ -1055,11 +1050,10 @@ static int virNetDevBridgeFDBAddDel(const virMacAddr *mac, const char *ifname, unsigned int flags, bool isAdd) { - int ret =3D -1; struct nlmsgerr *err; unsigned int recvbuflen; - struct nl_msg *nl_msg; struct ndmsg ndm =3D { .ndm_family =3D PF_BRIDGE, .ndm_state =3D NUD_N= OARP }; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (virNetDevGetIndex(ifname, &ndm.ndm_ifindex) < 0) @@ -1103,7 +1097,7 @@ virNetDevBridgeFDBAddDel(const virMacAddr *mac, const= char *ifname, =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) { - goto cleanup; + return -1; } if (recvbuflen < NLMSG_LENGTH(0) || resp =3D=3D NULL) goto malformed_resp; @@ -1116,7 +1110,7 @@ virNetDevBridgeFDBAddDel(const virMacAddr *mac, const= char *ifname, if (err->error) { virReportSystemError(-err->error, _("error adding fdb entry for %s"), ifnam= e); - goto cleanup; + return -1; } break; case NLMSG_DONE: @@ -1126,20 +1120,17 @@ virNetDevBridgeFDBAddDel(const virMacAddr *mac, con= st char *ifname, goto malformed_resp; } =20 - ret =3D 0; - cleanup: - nlmsg_free(nl_msg); - return ret; + return 0; =20 malformed_resp: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed netlink response message")); - goto cleanup; + return -1; =20 buffer_too_small: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714217224896.1336781780851; Wed, 8 Aug 2018 00:43:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 22E6612C30; Wed, 8 Aug 2018 07:43:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D58C31001F49; Wed, 8 Aug 2018 07:43:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6767D3F7CC; Wed, 8 Aug 2018 07:43:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hRb3005538 for ; Wed, 8 Aug 2018 03:43:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5403238192; Wed, 8 Aug 2018 07:43:27 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D45D5C480 for ; Wed, 8 Aug 2018 07:43:27 +0000 (UTC) Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) (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 3DD615D5EE for ; Wed, 8 Aug 2018 07:43:26 +0000 (UTC) Received: by mail-pl0-f67.google.com with SMTP id e11-v6so662438plb.3 for ; Wed, 08 Aug 2018 00:43:26 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=zD4K7A56pqBMV1DacCHCCui9ATMkWwkbIvMfOiR+stc=; b=LHRiDGGmlTBoa4cobjnh+CFUSqd0jgTCm+JeZ+e8HgEznOKfKCFpJCPQnT/j+1i042 mlnZM9bmad3F5L5AjzpI3cqD1XknMetgzFzqllP/w1ZWrFfxODHoIEgkfEen/Qxr7kDW jnm493HxeIfcz2idHmJBEMN0GU2m+AQWSMS5a6SK9nzM9PmobtbhCeTh1WYL2nnF1yTi KkdhaHTbpEYLb/49gU7klOHxGhAQZSXD6rxs9GHFcSMElTD4cZnmaUBC9Tmliqs+xqks OWJWXTPNs2T2tXQRQuW+G6sp+qAqa9KH2AM+INdL+zg4KB8Q+z56f00jxY5NDPBrLPyc 8EjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=zD4K7A56pqBMV1DacCHCCui9ATMkWwkbIvMfOiR+stc=; b=uJSS8GF/Sfb/ZrcUjuEVuYAuDLdQGb1Jn6PV3tW+XaWxXisiiOihywKcff3UhLd/tN DWBGrDThKg6IPEs5xCIO3fDA/l6eGAyLUy5E+deBtLXxSWOjP0Ka7TzFCPZeA/UsKska 8sv37agqTZfmyTBhZ3FyMCABWAlYmHB7PAboXkgLE18nJ02Ye/wUy1UtK35VxOZY1lvx GmQ+322eQi6G4CuKg8/XCLGwqKhWW8PVKdmRZYnlaxxGZSL1ouMyeEiKwayoMn9TjD6B tqGXRpU8L5GMFp4HRbIW+lG9JWI/xJ4ZUtb9WsCKw3kij5CGQAhpmfCVoOZ2khQf+GPk hfUw== X-Gm-Message-State: AOUpUlHds8ev02BArapDkj+XT0oNHAV+3tif+MQhAexdIaeYe4GbhD03 jMRWxVOBmn8YLKNgDHZVt6Bebtkd X-Google-Smtp-Source: AA+uWPy2nxbNFUVizqqvOz7Gj4PnWJg99/T2oNeJqD/afWB4MMm89mQqX++J7lkD4gDUDYxXf4Vz0A== X-Received: by 2002:a17:902:1e6:: with SMTP id b93-v6mr1515044plb.149.1533714205355; Wed, 08 Aug 2018 00:43:25 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:35 +0530 Message-Id: <1533501842-24503-9-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 08 Aug 2018 07:43:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 08 Aug 2018 07:43:26 +0000 (UTC) for IP:'209.85.160.67' DOMAIN:'mail-pl0-f67.google.com' HELO:'mail-pl0-f67.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.160.67 mail-pl0-f67.google.com 209.85.160.67 mail-pl0-f67.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 08/35] util: macaddr: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:43:35 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virMacAddrPtr is declared using VIR_AUTOPTR, the function virMacAddrFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar --- src/util/virmacaddr.c | 6 ++++++ src/util/virmacaddr.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/util/virmacaddr.c b/src/util/virmacaddr.c index 7afe032..e739775 100644 --- a/src/util/virmacaddr.c +++ b/src/util/virmacaddr.c @@ -252,3 +252,9 @@ virMacAddrIsBroadcastRaw(const unsigned char s[VIR_MAC_= BUFLEN]) { return memcmp(virMacAddrBroadcastAddrRaw, s, sizeof(*s)) =3D=3D 0; } + +void +virMacAddrFree(virMacAddrPtr addr) +{ + VIR_FREE(addr); +} diff --git a/src/util/virmacaddr.h b/src/util/virmacaddr.h index d0dd4a4..39dd51b 100644 --- a/src/util/virmacaddr.h +++ b/src/util/virmacaddr.h @@ -25,6 +25,7 @@ # define __VIR_MACADDR_H__ =20 # include "internal.h" +# include "viralloc.h" =20 # define VIR_MAC_BUFLEN 6 # define VIR_MAC_HEXLEN (VIR_MAC_BUFLEN * 2) @@ -64,5 +65,8 @@ int virMacAddrParseHex(const char* str, bool virMacAddrIsUnicast(const virMacAddr *addr); bool virMacAddrIsMulticast(const virMacAddr *addr); bool virMacAddrIsBroadcastRaw(const unsigned char s[VIR_MAC_BUFLEN]); +void virMacAddrFree(virMacAddrPtr addr); + +VIR_DEFINE_AUTOPTR_FUNC(virMacAddr, virMacAddrFree) =20 #endif /* __VIR_MACADDR_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714216629686.7027745863631; Wed, 8 Aug 2018 00:43:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 72DA649016; Wed, 8 Aug 2018 07:43:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B1F32015664; Wed, 8 Aug 2018 07:43:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E7EC118037F2; Wed, 8 Aug 2018 07:43:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.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 w787hW8H005564 for ; Wed, 8 Aug 2018 03:43:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id C9E443001A5A; Wed, 8 Aug 2018 07:43:32 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C29753001A41 for ; Wed, 8 Aug 2018 07:43:28 +0000 (UTC) Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) (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 E6B3C12C15 for ; Wed, 8 Aug 2018 07:43:27 +0000 (UTC) Received: by mail-pl0-f66.google.com with SMTP id ba4-v6so647858plb.11 for ; Wed, 08 Aug 2018 00:43:27 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=YUFwHnCZOccH4d0K4xsZYXlIl6Kzvlq02ElY4vYAHG8=; b=e43BrRkZkbcCP8EV48Nq7uAr0R654sGOZVRWaJ25AgE66xBR9hc8wwguTpOrxRMfn6 2NQN4myvAVtxE5/YkxpSGFjf72kkOI6Rt1pUvsrK//LaT+aFfK423H4eu0eo3ebAfQYa ip5kE34E4Bbib0FPiMHnCLihDefU/UJ84LnsGX5NEjFLI7JNoy9vLBu4FIbQU3o8wcaY 9rm+jAKixbGgPJ1mhrRTt+sF352IyOFTatSbZmdMANxq/RyrFyx6Qc2b61B2SiVmsGq5 l6mUztzEV1VNf1JXLM3IHVnjyq8z22haQXyw4WKpkDzXv6FzX11HajWSzqONT3uU7t3L JgEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=YUFwHnCZOccH4d0K4xsZYXlIl6Kzvlq02ElY4vYAHG8=; b=qxdLDgMdhgC0kMn2+pJioDWHxh/Vj3zGjtuK4f1/H+xv70gMCXJs3Ut9TObpOenxG4 tiyH0nAhc8QsNL2df0gBnFopqNyEMdTITiNa5AmAzngYic+NcwFlQEAyY2IMeBaAAy50 j0i9z1kTLfmsAoS1mHtXNUKiHCdQhbhrP0WC0xOSFQTTHt9bb+lqQASHsrRSx5c1z+Tm TEPQkpNqyq1s0GbMd3guDF95kvjt/k8vkEgP4kA4s7MnKuj79J1pB5tyVWSi7mOfEheM kmpMfWavZLFXALRthbbBuOt71Phtnb6cm2Vqh8fTIld05MIz3fl9bqU66237CI6A/grw qLSQ== X-Gm-Message-State: AOUpUlH5x2ZdiQ/55FshzWhedzemFv45huMSggmtfX9yeQLRPA0nZjFn GYMVWGuKMhN3RMWmiMzTfte81NDQ X-Google-Smtp-Source: AA+uWPxHSCY2hV1Rwaznc4rd8jH4SNvjEwxX7vuXJiIpVC+I4ttCPxHHfgvz/ZE7RNioaSHDy/ZJfQ== X-Received: by 2002:a17:902:9884:: with SMTP id s4-v6mr1500169plp.127.1533714207169; Wed, 08 Aug 2018 00:43:27 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:36 +0530 Message-Id: <1533501842-24503-10-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:43:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:43:28 +0000 (UTC) for IP:'209.85.160.66' DOMAIN:'mail-pl0-f66.google.com' HELO:'mail-pl0-f66.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.160.66 mail-pl0-f66.google.com 209.85.160.66 mail-pl0-f66.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 09/35] util: netdev: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 08 Aug 2018 07:43:35 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When variables of type virNetDevRxFilterPtr and virNetDevMcastEntryPtr are declared using VIR_AUTOPTR, the functions virNetDevRxFilterFree and virNetDevMcastEntryFree, respectively, will be run automatically on them when they go out of scope. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdev.c | 9 ++++++++- src/util/virnetdev.h | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 0777eca..9eca786 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -29,7 +29,6 @@ #include "virfile.h" #include "virerror.h" #include "vircommand.h" -#include "viralloc.h" #include "virpci.h" #include "virlog.h" #include "virstring.h" @@ -120,6 +119,14 @@ struct _virNetDevMcastEntry { virMacAddr macaddr; }; =20 +static void +virNetDevMcastEntryFree(virNetDevMcastEntryPtr entry) +{ + VIR_FREE(entry); +} + +VIR_DEFINE_AUTOPTR_FUNC(virNetDevMcastEntry, virNetDevMcastEntryFree) + typedef struct _virNetDevMcastList virNetDevMcastList; typedef virNetDevMcastList *virNetDevMcastListPtr; struct _virNetDevMcastList { diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 71eaf45..8860ea1 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -30,6 +30,7 @@ # include "virmacaddr.h" # include "virpci.h" # include "virnetdevvlan.h" +# include "viralloc.h" =20 # ifdef HAVE_STRUCT_IFREQ typedef struct ifreq virIfreq; @@ -313,4 +314,7 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link, =20 int virNetDevRunEthernetScript(const char *ifname, const char *script) ATTRIBUTE_NOINLINE; + +VIR_DEFINE_AUTOPTR_FUNC(virNetDevRxFilter, virNetDevRxFilterFree) + #endif /* __VIR_NETDEV_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153371421912647.216006076011695; Wed, 8 Aug 2018 00:43:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C8493BEB9; Wed, 8 Aug 2018 07:43:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D77C308BDA4; Wed, 8 Aug 2018 07:43:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B026318037F3; Wed, 8 Aug 2018 07:43:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hY2W005576 for ; Wed, 8 Aug 2018 03:43:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 774441001F58; Wed, 8 Aug 2018 07:43:34 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C9321001F49 for ; Wed, 8 Aug 2018 07:43:32 +0000 (UTC) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) (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 8259F12C36 for ; Wed, 8 Aug 2018 07:43:30 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id d4-v6so731816pfn.0 for ; Wed, 08 Aug 2018 00:43:30 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=wM23RG5V4e8Ui2JeloUpfqNL6vec0/WNB8YfTH0M0io=; b=sQoC7T72aJlWUzw/aK9hoEJrqhM+NAqKWnn4L5IONBkWCn/NwXch7CdpMN7C7sW1CW 3/6YMcJ6c2e+ckZuIGGIdbMIHbt3J2DaJVelcHWbmNjQZgqDVtf7HwynVNRzCegeN10n cxxAhoFejjFqnV4V2bXnfucTQOXSU+oySLqFJFgWbNeHwwQT3vtSEgQy71OzBNPwu7Or T3t/RdIlOTCbW/S9qMZ1zBpgtXTuE5ZxABtRc0VR36Rw98yd6gI8O4ZldtmjlJ8HIwt2 4NBHYIdjtyJ4enhkl9Sf+AaYiMOBx022O4C2+B2csVue3Wy4oXaWB0jmFOhkg37ZsYTi 2+IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=wM23RG5V4e8Ui2JeloUpfqNL6vec0/WNB8YfTH0M0io=; b=jpJCK3tqTi7Kh1EgBsmFvYPPaMPh/9ZRyLDSFZgPte6yuLgxrqU4aEjWY3xjYxHTCz AbOTgChE+pvpqlu1qkVh2P5tpWpKCc05XRzhQfYWM0ZEZghuRpWw6jWxyPYtHrZ+THPT YAfeCQcEqKtzyJ7siNo7HnAUg3d6u0rkT0PHXhsKAuHn5XhIWhqrUJaNoXcB+le1ahoM niEc6fpa9fCTW1kZS4Kq/QPefmMVaAJ2DC7PM8USgxlyM/dhlJTIfDFERAJQT2fSHzGu WjK7sXoWs1UaHm7e/3YNvmJWkelOGrg97S5ijN5N/jOpXDAa4LA7iZkv9fDJmVN1hv1u rhOA== X-Gm-Message-State: AOUpUlEfAyuzvBb0wNtGsCSS6zepcqc7Se4vnPlMvVis2aMNvuo4bR2y ntjiadItXmvIvVUv6uD0Ty6lKCT6 X-Google-Smtp-Source: AA+uWPyzGAIDfw8rjLMtNrcJ+JNMT1VDfe433oDe4hFnZg93YdnClUOHeuSDfRfJweklpHYKlgaiUA== X-Received: by 2002:a63:fd52:: with SMTP id m18-v6mr1464029pgj.304.1533714209657; Wed, 08 Aug 2018 00:43:29 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:37 +0530 Message-Id: <1533501842-24503-11-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:43:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:43:30 +0000 (UTC) for IP:'209.85.210.193' DOMAIN:'mail-pf1-f193.google.com' HELO:'mail-pf1-f193.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.210.193 mail-pf1-f193.google.com 209.85.210.193 mail-pf1-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 10/35] util: netdev: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:43:37 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdev.c | 328 +++++++++++++++++++----------------------------= ---- 1 file changed, 119 insertions(+), 209 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 9eca786..5651f6f 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -535,18 +535,17 @@ int virNetDevSetMTUFromDevice(const char *ifname, */ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs) { - int ret =3D -1; - char *pid =3D NULL; - char *phy =3D NULL; - char *phy_path =3D NULL; int len; + VIR_AUTOFREE(char *) pid =3D NULL; + VIR_AUTOFREE(char *) phy =3D NULL; + VIR_AUTOFREE(char *) phy_path =3D NULL; =20 if (virAsprintf(&pid, "%lld", (long long) pidInNs) =3D=3D -1) return -1; =20 /* The 802.11 wireless devices only move together with their PHY. */ if (virNetDevSysfsFile(&phy_path, ifname, "phy80211/name") < 0) - goto cleanup; + return -1; =20 if ((len =3D virFileReadAllQuiet(phy_path, 1024, &phy)) <=3D 0) { /* Not a wireless device. */ @@ -556,7 +555,7 @@ int virNetDevSetNamespace(const char *ifname, pid_t pid= InNs) =20 argv[5] =3D pid; if (virRun(argv, NULL) < 0) - goto cleanup; + return -1; =20 } else { const char *argv[] =3D { @@ -569,15 +568,10 @@ int virNetDevSetNamespace(const char *ifname, pid_t p= idInNs) argv[2] =3D phy; argv[5] =3D pid; if (virRun(argv, NULL) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(phy_path); - VIR_FREE(phy); - VIR_FREE(pid); - return ret; + return 0; } =20 #if defined(SIOCSIFNAME) && defined(HAVE_STRUCT_IFREQ) @@ -969,25 +963,21 @@ int virNetDevGetIndex(const char *ifname ATTRIBUTE_UN= USED, int virNetDevGetMaster(const char *ifname, char **master) { - int ret =3D -1; - void *nlData =3D NULL; struct nlattr *tb[IFLA_MAX + 1] =3D {NULL, }; + VIR_AUTOFREE(void *) nlData =3D NULL; =20 *master =3D NULL; =20 if (virNetlinkDumpLink(ifname, -1, &nlData, tb, 0, 0) < 0) - goto cleanup; + return -1; =20 if (tb[IFLA_MASTER]) { if (!(*master =3D virNetDevGetName(*(int *)RTA_DATA(tb[IFLA_MASTER= ])))) - goto cleanup; + return -1; } =20 VIR_DEBUG("IFLA_MASTER for %s is %s", ifname, *master ? *master : "(no= ne)"); - ret =3D 0; - cleanup: - VIR_FREE(nlData); - return ret; + return 0; } =20 =20 @@ -1168,39 +1158,33 @@ virNetDevSysfsDeviceFile(char **pf_sysfs_device_lin= k, const char *ifname, static bool virNetDevIsPCIDevice(const char *devpath) { - char *subsys_link =3D NULL; - char *abs_path =3D NULL; char *subsys =3D NULL; - bool ret =3D false; + VIR_AUTOFREE(char *) subsys_link =3D NULL; + VIR_AUTOFREE(char *) abs_path =3D NULL; =20 if (virAsprintf(&subsys_link, "%s/subsystem", devpath) < 0) return false; =20 if (!virFileExists(subsys_link)) - goto cleanup; + return false; =20 if (virFileResolveLink(subsys_link, &abs_path) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to resolve device subsystem symlink %s"), subsys_link); - goto cleanup; + return false; } =20 subsys =3D last_component(abs_path); - ret =3D STRPREFIX(subsys, "pci"); - - cleanup: - VIR_FREE(subsys_link); - VIR_FREE(abs_path); - return ret; + return STRPREFIX(subsys, "pci"); } =20 static virPCIDevicePtr virNetDevGetPCIDevice(const char *devName) { - char *vfSysfsDevicePath =3D NULL; virPCIDeviceAddressPtr vfPCIAddr =3D NULL; virPCIDevicePtr vfPCIDevice =3D NULL; + VIR_AUTOFREE(char *) vfSysfsDevicePath =3D NULL; =20 if (virNetDevSysfsFile(&vfSysfsDevicePath, devName, "device") < 0) goto cleanup; @@ -1216,7 +1200,6 @@ virNetDevGetPCIDevice(const char *devName) vfPCIAddr->slot, vfPCIAddr->function); =20 cleanup: - VIR_FREE(vfSysfsDevicePath); VIR_FREE(vfPCIAddr); =20 return vfPCIDevice; @@ -1241,25 +1224,20 @@ int virNetDevGetPhysPortID(const char *ifname, char **physPortID) { - int ret =3D -1; - char *physPortIDFile =3D NULL; + VIR_AUTOFREE(char *) physPortIDFile =3D NULL; =20 *physPortID =3D NULL; =20 if (virNetDevSysfsFile(&physPortIDFile, ifname, "phys_port_id") < 0) - goto cleanup; + return -1; =20 /* a failure to read just means the driver doesn't support - * phys_port_id, so set success now and ignore the return from - * virFileReadAllQuiet(). + * phys_port_id, so ignore the return from virFileReadAllQuiet() + * and return success. */ - ret =3D 0; - ignore_value(virFileReadAllQuiet(physPortIDFile, 1024, physPortID)); =20 - cleanup: - VIR_FREE(physPortIDFile); - return ret; + return 0; } =20 =20 @@ -1280,67 +1258,61 @@ virNetDevGetVirtualFunctions(const char *pfname, size_t *n_vfname, unsigned int *max_vfs) { - int ret =3D -1; size_t i; - char *pf_sysfs_device_link =3D NULL; - char *pci_sysfs_device_link =3D NULL; - char *pciConfigAddr =3D NULL; - char *pfPhysPortID =3D NULL; + VIR_AUTOFREE(char *) pf_sysfs_device_link =3D NULL; + VIR_AUTOFREE(char *) pci_sysfs_device_link =3D NULL; + VIR_AUTOFREE(char *) pciConfigAddr =3D NULL; + VIR_AUTOFREE(char *) pfPhysPortID =3D NULL; + VIR_AUTOFREE(char **) tmpVfname =3D NULL; + VIR_AUTOFREE(virPCIDeviceAddressPtr *) tmpVirtFns =3D NULL; =20 *virt_fns =3D NULL; *n_vfname =3D 0; *max_vfs =3D 0; =20 if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) - goto cleanup; + return -1; =20 if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) - goto cleanup; + return -1; =20 - if (virPCIGetVirtualFunctions(pf_sysfs_device_link, virt_fns, - n_vfname, max_vfs) < 0) - goto cleanup; + if (virPCIGetVirtualFunctions(pf_sysfs_device_link, &tmpVirtFns, + n_vfname, max_vfs) < 0) { + return -1; + } =20 - if (VIR_ALLOC_N(*vfname, *n_vfname) < 0) - goto cleanup; + if (VIR_ALLOC_N(tmpVfname, *n_vfname) < 0) + return -1; =20 for (i =3D 0; i < *n_vfname; i++) { - if (virPCIGetAddrString((*virt_fns)[i]->domain, - (*virt_fns)[i]->bus, - (*virt_fns)[i]->slot, - (*virt_fns)[i]->function, + if (virPCIGetAddrString(tmpVirtFns[i]->domain, + tmpVirtFns[i]->bus, + tmpVirtFns[i]->slot, + tmpVirtFns[i]->function, &pciConfigAddr) < 0) { virReportSystemError(ENOSYS, "%s", _("Failed to get PCI Config Address Strin= g")); - goto cleanup; + return -1; } if (virPCIGetSysfsFile(pciConfigAddr, &pci_sysfs_device_link) < 0)= { virReportSystemError(ENOSYS, "%s", _("Failed to get PCI SYSFS file")); - goto cleanup; + return -1; } =20 if (virPCIGetNetName(pci_sysfs_device_link, 0, - pfPhysPortID, &((*vfname)[i])) < 0) { - goto cleanup; + pfPhysPortID, &tmpVfname[i]) < 0) { + return -1; } =20 - if (!(*vfname)[i]) + if (!tmpVfname[i]) VIR_INFO("VF does not have an interface name"); } =20 - ret =3D 0; + VIR_STEAL_PTR(*vfname, tmpVfname); + VIR_STEAL_PTR(*virt_fns, tmpVirtFns); =20 - cleanup: - if (ret < 0) { - VIR_FREE(*vfname); - VIR_FREE(*virt_fns); - } - VIR_FREE(pfPhysPortID); - VIR_FREE(pf_sysfs_device_link); - VIR_FREE(pci_sysfs_device_link); - VIR_FREE(pciConfigAddr); - return ret; + return 0; } =20 /** @@ -1355,17 +1327,12 @@ virNetDevGetVirtualFunctions(const char *pfname, int virNetDevIsVirtualFunction(const char *ifname) { - char *if_sysfs_device_link =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) if_sysfs_device_link =3D NULL; =20 if (virNetDevSysfsFile(&if_sysfs_device_link, ifname, "device") < 0) - return ret; + return -1; =20 - ret =3D virPCIIsVirtualFunction(if_sysfs_device_link); - - VIR_FREE(if_sysfs_device_link); - - return ret; + return virPCIIsVirtualFunction(if_sysfs_device_link); } =20 /** @@ -1383,25 +1350,19 @@ int virNetDevGetVirtualFunctionIndex(const char *pfname, const char *vfname, int *vf_index) { - char *pf_sysfs_device_link =3D NULL, *vf_sysfs_device_link =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) pf_sysfs_device_link =3D NULL; + VIR_AUTOFREE(char *) vf_sysfs_device_link =3D NULL; =20 if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) - return ret; + return -1; =20 - if (virNetDevSysfsFile(&vf_sysfs_device_link, vfname, "device") < 0) { - VIR_FREE(pf_sysfs_device_link); - return ret; - } + if (virNetDevSysfsFile(&vf_sysfs_device_link, vfname, "device") < 0) + return -1; =20 - ret =3D virPCIGetVirtualFunctionIndex(pf_sysfs_device_link, + return virPCIGetVirtualFunctionIndex(pf_sysfs_device_link, vf_sysfs_device_link, vf_index); =20 - VIR_FREE(pf_sysfs_device_link); - VIR_FREE(vf_sysfs_device_link); - - return ret; } =20 /** @@ -1417,19 +1378,18 @@ virNetDevGetVirtualFunctionIndex(const char *pfname= , const char *vfname, int virNetDevGetPhysicalFunction(const char *ifname, char **pfname) { - char *physfn_sysfs_path =3D NULL; - char *vfPhysPortID =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) physfn_sysfs_path =3D NULL; + VIR_AUTOFREE(char *) vfPhysPortID =3D NULL; =20 if (virNetDevGetPhysPortID(ifname, &vfPhysPortID) < 0) - goto cleanup; + return -1; =20 if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") < 0) - goto cleanup; + return -1; =20 if (virPCIGetNetName(physfn_sysfs_path, 0, vfPhysPortID, pfname) < 0) { - goto cleanup; + return -1; } =20 if (!*pfname) { @@ -1439,14 +1399,10 @@ virNetDevGetPhysicalFunction(const char *ifname, ch= ar **pfname) virReportError(VIR_ERR_INTERNAL_ERROR, _("The PF device for VF %s has no network device na= me"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(vfPhysPortID); - VIR_FREE(physfn_sysfs_path); - return ret; + return 0; } =20 =20 @@ -1470,26 +1426,25 @@ virNetDevGetPhysicalFunction(const char *ifname, ch= ar **pfname) int virNetDevPFGetVF(const char *pfname, int vf, char **vfname) { - char *virtfnName =3D NULL; - char *virtfnSysfsPath =3D NULL; - char *pfPhysPortID =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) virtfnName =3D NULL; + VIR_AUTOFREE(char *) virtfnSysfsPath =3D NULL; + VIR_AUTOFREE(char *) pfPhysPortID =3D NULL; =20 /* a VF may have multiple "ports", each one having its own netdev, * and each netdev having a different phys_port_id. Be sure we get * the VF netdev with a phys_port_id matchine that of pfname */ if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) - goto cleanup; + return -1; =20 if (virAsprintf(&virtfnName, "virtfn%d", vf) < 0) - goto cleanup; + return -1; =20 /* this provides the path to the VF's directory in sysfs, * e.g. "/sys/class/net/enp2s0f0/virtfn3" */ if (virNetDevSysfsDeviceFile(&virtfnSysfsPath, pfname, virtfnName) < 0) - goto cleanup; + return -1; =20 /* and this gets the netdev name associated with it, which is a * directory entry in [virtfnSysfsPath]/net, @@ -1498,14 +1453,7 @@ virNetDevPFGetVF(const char *pfname, int vf, char **= vfname) * isn't bound to a netdev driver, it won't have a netdev name, * and vfname will be NULL). */ - ret =3D virPCIGetNetName(virtfnSysfsPath, 0, pfPhysPortID, vfname); - - cleanup: - VIR_FREE(virtfnName); - VIR_FREE(virtfnSysfsPath); - VIR_FREE(pfPhysPortID); - - return ret; + return virPCIGetNetName(virtfnSysfsPath, 0, pfPhysPortID, vfname); } =20 =20 @@ -1522,30 +1470,24 @@ int virNetDevGetVirtualFunctionInfo(const char *vfname, char **pfname, int *vf) { - char *pf_sysfs_path =3D NULL, *vf_sysfs_path =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) pf_sysfs_path =3D NULL; + VIR_AUTOFREE(char *) vf_sysfs_path =3D NULL; + VIR_AUTOFREE(char *) tmpPfname =3D NULL; =20 *pfname =3D NULL; =20 - if (virNetDevGetPhysicalFunction(vfname, pfname) < 0) - return ret; + if (virNetDevGetPhysicalFunction(vfname, &tmpPfname) < 0) + return -1; =20 - if (virNetDevSysfsFile(&pf_sysfs_path, *pfname, "device") < 0) - goto cleanup; + if (virNetDevSysfsFile(&pf_sysfs_path, tmpPfname, "device") < 0) + return -1; =20 if (virNetDevSysfsFile(&vf_sysfs_path, vfname, "device") < 0) - goto cleanup; + return -1; =20 - ret =3D virPCIGetVirtualFunctionIndex(pf_sysfs_path, vf_sysfs_path, vf= ); + VIR_STEAL_PTR(*pfname, tmpPfname); =20 - cleanup: - if (ret < 0) - VIR_FREE(*pfname); - - VIR_FREE(vf_sysfs_path); - VIR_FREE(pf_sysfs_path); - - return ret; + return virPCIGetVirtualFunctionIndex(pf_sysfs_path, vf_sysfs_path, vf); } =20 #else /* !__linux__ */ @@ -1657,7 +1599,6 @@ virNetDevSetVfConfig(const char *ifname, int vf, { int rc =3D -1; char macstr[VIR_MAC_STRING_BUFLEN]; - struct nlmsghdr *resp =3D NULL; struct nlmsgerr *err; unsigned int recvbuflen =3D 0; struct nl_msg *nl_msg; @@ -1666,6 +1607,7 @@ virNetDevSetVfConfig(const char *ifname, int vf, .ifi_family =3D AF_UNSPEC, .ifi_index =3D -1, }; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!macaddr && vlanid < 0) return -1; @@ -1769,7 +1711,6 @@ virNetDevSetVfConfig(const char *ifname, int vf, vlanid, rc < 0 ? "Fail" : "Success"); =20 nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -1843,19 +1784,15 @@ virNetDevGetVfConfig(const char *ifname, int vf, vi= rMacAddrPtr mac, int *vlanid) { int rc =3D -1; - void *nlData =3D NULL; struct nlattr *tb[IFLA_MAX + 1] =3D {NULL, }; int ifindex =3D -1; + VIR_AUTOFREE(void *) nlData =3D NULL; =20 rc =3D virNetlinkDumpLink(ifname, ifindex, &nlData, tb, 0, 0); if (rc < 0) - goto cleanup; + return rc; =20 - rc =3D virNetDevParseVfConfig(tb, vf, mac, vlanid); - - cleanup: - VIR_FREE(nlData); - return rc; + return virNetDevParseVfConfig(tb, vf, mac, vlanid); } =20 =20 @@ -1914,14 +1851,14 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, { int ret =3D -1; const char *pfDevName =3D NULL; - char *pfDevOrig =3D NULL; - char *vfDevOrig =3D NULL; virMacAddr oldMAC; char MACStr[VIR_MAC_STRING_BUFLEN]; int oldVlanTag =3D -1; - char *filePath =3D NULL; - char *fileStr =3D NULL; virJSONValuePtr configJSON =3D NULL; + VIR_AUTOFREE(char *) pfDevOrig =3D NULL; + VIR_AUTOFREE(char *) vfDevOrig =3D NULL; + VIR_AUTOFREE(char *) filePath =3D NULL; + VIR_AUTOFREE(char *) fileStr =3D NULL; =20 if (vf >=3D 0) { /* linkdev is the PF */ @@ -2030,10 +1967,6 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, =20 ret =3D 0; cleanup: - VIR_FREE(pfDevOrig); - VIR_FREE(vfDevOrig); - VIR_FREE(filePath); - VIR_FREE(fileStr); virJSONValueFree(configJSON); return ret; } @@ -2069,14 +2002,14 @@ virNetDevReadNetConfig(const char *linkdev, int vf, { int ret =3D -1; const char *pfDevName =3D NULL; - char *pfDevOrig =3D NULL; - char *vfDevOrig =3D NULL; - char *filePath =3D NULL; - char *fileStr =3D NULL; virJSONValuePtr configJSON =3D NULL; const char *MACStr =3D NULL; const char *adminMACStr =3D NULL; int vlanTag =3D -1; + VIR_AUTOFREE(char *) pfDevOrig =3D NULL; + VIR_AUTOFREE(char *) vfDevOrig =3D NULL; + VIR_AUTOFREE(char *) filePath =3D NULL; + VIR_AUTOFREE(char *) fileStr =3D NULL; =20 *adminMAC =3D NULL; *vlan =3D NULL; @@ -2245,10 +2178,6 @@ virNetDevReadNetConfig(const char *linkdev, int vf, VIR_FREE(*vlan); } =20 - VIR_FREE(pfDevOrig); - VIR_FREE(vfDevOrig); - VIR_FREE(filePath); - VIR_FREE(fileStr); virJSONValueFree(configJSON); return ret; } @@ -2282,10 +2211,10 @@ virNetDevSetNetConfig(const char *linkdev, int vf, int ret =3D -1; char MACStr[VIR_MAC_STRING_BUFLEN]; const char *pfDevName =3D NULL; - char *pfDevOrig =3D NULL; - char *vfDevOrig =3D NULL; int vlanTag =3D -1; virPCIDevicePtr vfPCIDevice =3D NULL; + VIR_AUTOFREE(char *) pfDevOrig =3D NULL; + VIR_AUTOFREE(char *) vfDevOrig =3D NULL; =20 if (vf >=3D 0) { /* linkdev is the PF */ @@ -2462,8 +2391,6 @@ virNetDevSetNetConfig(const char *linkdev, int vf, =20 ret =3D 0; cleanup: - VIR_FREE(pfDevOrig); - VIR_FREE(vfDevOrig); virPCIDeviceFree(vfPCIDevice); return ret; } @@ -2543,28 +2470,27 @@ int virNetDevGetLinkInfo(const char *ifname, virNetDevIfLinkPtr lnk) { - int ret =3D -1; - char *path =3D NULL; - char *buf =3D NULL; char *tmp; int tmp_state; unsigned int tmp_speed; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (virNetDevSysfsFile(&path, ifname, "operstate") < 0) - goto cleanup; + return -1; =20 if (virFileReadAll(path, 1024, &buf) < 0) { virReportSystemError(errno, _("unable to read: %s"), path); - goto cleanup; + return -1; } =20 if (!(tmp =3D strchr(buf, '\n'))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); - goto cleanup; + return -1; } =20 *tmp =3D '\0'; @@ -2575,7 +2501,7 @@ virNetDevGetLinkInfo(const char *ifname, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); - goto cleanup; + return -1; } =20 lnk->state =3D tmp_state; @@ -2586,26 +2512,24 @@ virNetDevGetLinkInfo(const char *ifname, * speed if that's the case. */ if (lnk->state !=3D VIR_NETDEV_IF_STATE_UP) { lnk->speed =3D 0; - ret =3D 0; - goto cleanup; + return 0; } =20 VIR_FREE(path); VIR_FREE(buf); =20 if (virNetDevSysfsFile(&path, ifname, "speed") < 0) - goto cleanup; + return -1; =20 if (virFileReadAllQuiet(path, 1024, &buf) < 0) { /* Some devices doesn't report speed, in which case we get EINVAL = */ - if (errno =3D=3D EINVAL) { - ret =3D 0; - goto cleanup; - } + if (errno =3D=3D EINVAL) + return 0; + virReportSystemError(errno, _("unable to read: %s"), path); - goto cleanup; + return -1; } =20 if (virStrToLong_ui(buf, &tmp, 10, &tmp_speed) < 0 || @@ -2613,16 +2537,12 @@ virNetDevGetLinkInfo(const char *ifname, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); - goto cleanup; + return -1; } =20 lnk->speed =3D tmp_speed; =20 - ret =3D 0; - cleanup: - VIR_FREE(buf); - VIR_FREE(path); - return ret; + return 0; } =20 #else @@ -2830,10 +2750,10 @@ static int virNetDevGetMcastList(const char *ifname, virNetDevMcastListPtr mcast) { char *cur =3D NULL; - char *buf =3D NULL; char *next =3D NULL; int ret =3D -1, len; virNetDevMcastEntryPtr entry =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 mcast->entries =3D NULL; mcast->nentries =3D 0; @@ -2866,7 +2786,6 @@ static int virNetDevGetMcastList(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(buf); VIR_FREE(entry); =20 return ret; @@ -3006,13 +2925,11 @@ static int virNetDevRDMAFeature(const char *ifname, virBitmapPtr *out) { - char *eth_devpath =3D NULL; - char *ib_devpath =3D NULL; - char *eth_res_buf =3D NULL; - char *ib_res_buf =3D NULL; DIR *dirp =3D NULL; struct dirent *dp; int ret =3D -1; + VIR_AUTOFREE(char *) eth_devpath =3D NULL; + VIR_AUTOFREE(char *) eth_res_buf =3D NULL; =20 if (!virFileExists(SYSFS_INFINIBAND_DIR)) return 0; @@ -3028,6 +2945,9 @@ virNetDevRDMAFeature(const char *ifname, goto cleanup; =20 while (virDirRead(dirp, &dp, SYSFS_INFINIBAND_DIR) > 0) { + VIR_AUTOFREE(char *) ib_devpath =3D NULL; + VIR_AUTOFREE(char *) ib_res_buf =3D NULL; + if (virAsprintf(&ib_devpath, SYSFS_INFINIBAND_DIR "%s/device/resou= rce", dp->d_name) < 0) continue; @@ -3036,17 +2956,11 @@ virNetDevRDMAFeature(const char *ifname, ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_RDMA)); break; } - VIR_FREE(ib_devpath); - VIR_FREE(ib_res_buf); } ret =3D 0; =20 cleanup: VIR_DIR_CLOSE(dirp); - VIR_FREE(eth_devpath); - VIR_FREE(ib_devpath); - VIR_FREE(eth_res_buf); - VIR_FREE(ib_res_buf); return ret; } =20 @@ -3205,11 +3119,11 @@ static uint32_t virNetDevGetFamilyId(const char *family_name) { struct nl_msg *nl_msg =3D NULL; - struct nlmsghdr *resp =3D NULL; struct genlmsghdr* gmsgh =3D NULL; struct nlattr *tb[CTRL_ATTR_MAX + 1] =3D {NULL, }; unsigned int recvbuflen; uint32_t family_id =3D 0; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!(nl_msg =3D nlmsg_alloc_simple(GENL_ID_CTRL, NLM_F_REQUEST | NLM_F_ACK))) { @@ -3245,7 +3159,6 @@ virNetDevGetFamilyId(const char *family_name) =20 cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return family_id; } =20 @@ -3265,16 +3178,16 @@ virNetDevSwitchdevFeature(const char *ifname, virBitmapPtr *out) { struct nl_msg *nl_msg =3D NULL; - struct nlmsghdr *resp =3D NULL; unsigned int recvbuflen; struct nlattr *tb[DEVLINK_ATTR_MAX + 1] =3D {NULL, }; virPCIDevicePtr pci_device_ptr =3D NULL; struct genlmsghdr* gmsgh =3D NULL; const char *pci_name; - char *pfname =3D NULL; int is_vf =3D -1; int ret =3D -1; uint32_t family_id; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + VIR_AUTOFREE(char *) pfname =3D NULL; =20 if ((family_id =3D virNetDevGetFamilyId(DEVLINK_GENL_NAME)) <=3D 0) return ret; @@ -3333,8 +3246,6 @@ virNetDevSwitchdevFeature(const char *ifname, cleanup: nlmsg_free(nl_msg); virPCIDeviceFree(pci_device_ptr); - VIR_FREE(resp); - VIR_FREE(pfname); return ret; } # else @@ -3375,7 +3286,7 @@ virNetDevGetEthtoolGFeatures(virBitmapPtr bitmap, int fd, struct ifreq *ifr) { - struct ethtool_gfeatures *g_cmd; + VIR_AUTOFREE(struct ethtool_gfeatures *) g_cmd =3D NULL; =20 if (VIR_ALLOC_VAR(g_cmd, struct ethtool_get_features_block, GFEATURES_SIZE) <= 0) @@ -3385,7 +3296,6 @@ virNetDevGetEthtoolGFeatures(virBitmapPtr bitmap, g_cmd->size =3D GFEATURES_SIZE; if (virNetDevGFeatureAvailable(fd, ifr, g_cmd)) ignore_value(virBitmapSetBit(bitmap, VIR_NET_DEV_FEAT_TXUDPTNL)); - VIR_FREE(g_cmd); return 0; } # else --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714221932797.0094587560308; Wed, 8 Aug 2018 00:43:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3AD0012C15; Wed, 8 Aug 2018 07:43:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02A771001F49; Wed, 8 Aug 2018 07:43:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A7DC418037F7; Wed, 8 Aug 2018 07:43:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hYjE005581 for ; Wed, 8 Aug 2018 03:43:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id E25E0308BDB3; Wed, 8 Aug 2018 07:43:34 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D911E308BDA4 for ; Wed, 8 Aug 2018 07:43:34 +0000 (UTC) Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 0B38530832C8 for ; Wed, 8 Aug 2018 07:43:33 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id k21-v6so706886pff.11 for ; Wed, 08 Aug 2018 00:43:33 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=lfw5mTgNm9GCvh+TreNXjxL+tUD1a3DxP1okThCoybA=; b=HmLO9568HUFD6jnf21H1N4NI5jAE69ylrZmYCZIAmnl/2w53YIRQCq8Giosi0Jajoy gGQau8JtFlfiUCqW+GDSwYVxSsjsdn6d4QzqXMVbHTE8MV9hj8OvI5ky6EYChd5ijmSb LUt+WqPpHmfH9fdAz4i5uo0SiYDK0+L2gDMNDuQnH7eDsMm/kF60kW5FBdTw0rFxaMZI paig4ThhKeEyfba+kLGo1zYxi9DQc5kv1DMncCqBIJTaY4vlvp13wI3yKipkEdyewRqi 5mCkJRpwL2ANkZGnlptuXzAM8Vvb7YOMtxpV6zc0bHh+lbKNN8uonsyF6p/2fUo3v929 5Z/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=lfw5mTgNm9GCvh+TreNXjxL+tUD1a3DxP1okThCoybA=; b=Yw0VvMc144Jg09eIXAGYwkXL4eS8tizaGoWlAXvyK4zmlzOLSjOGvnHB+kysudB6KO X8JVsAj7LA+1LwSLf4yeCfCX6qRU20za+3ND6Czki/CHZxICnelUc+nMkxXVEpR7Magj mVPKqojs4zAsJUl6RhTwQKonPUlliZmCWWOD3AOcoGuSpyA3gsPQvrQZGFzM1kA4NCqV lb64t0bGIkIJpOO/lkMZpbLwPf5ByvuMDqZ6w+9viVas6EM5SuYg+iGM5tsTG+BlxMKD B0nrEFH7ytsBiZBKCCX1H97YDaNWFbmBi7FrlbfXSAPqZY0H0s/2dpdSu3ZyuA5ppxIQ PfhQ== X-Gm-Message-State: AOUpUlHOFrPz9IL+RnHH5LPEeVHiAftE98WDrbQ44T4+Zzr/UDOx3xtV oBaKGcCSKHBf4gpG0796HxWoo/xE X-Google-Smtp-Source: AA+uWPwUIAuRUp6nhvIU0WA5mYKNvjI2NFJOQQ9PQeuhfg9V6GpM8+YKq+tcQ4qOmPR2CgyCQrj9lw== X-Received: by 2002:a63:175b:: with SMTP id 27-v6mr1432242pgx.31.1533714212094; Wed, 08 Aug 2018 00:43:32 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:38 +0530 Message-Id: <1533501842-24503-12-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:43:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:43:33 +0000 (UTC) for IP:'209.85.210.180' DOMAIN:'mail-pf1-f180.google.com' HELO:'mail-pf1-f180.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.210.180 mail-pf1-f180.google.com 209.85.210.180 mail-pf1-f180.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 11/35] util: netdev: use VIR_AUTOPTR for aggregate types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:43:39 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdev.c | 267 +++++++++++++++++++++--------------------------= ---- 1 file changed, 110 insertions(+), 157 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 5651f6f..d5aa94c 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1182,27 +1182,21 @@ virNetDevIsPCIDevice(const char *devpath) static virPCIDevicePtr virNetDevGetPCIDevice(const char *devName) { - virPCIDeviceAddressPtr vfPCIAddr =3D NULL; - virPCIDevicePtr vfPCIDevice =3D NULL; + VIR_AUTOPTR(virPCIDeviceAddress) vfPCIAddr =3D NULL; VIR_AUTOFREE(char *) vfSysfsDevicePath =3D NULL; =20 if (virNetDevSysfsFile(&vfSysfsDevicePath, devName, "device") < 0) - goto cleanup; + return NULL; =20 if (!virNetDevIsPCIDevice(vfSysfsDevicePath)) - goto cleanup; + return NULL; =20 vfPCIAddr =3D virPCIGetDeviceAddressFromSysfsLink(vfSysfsDevicePath); if (!vfPCIAddr) - goto cleanup; + return NULL; =20 - vfPCIDevice =3D virPCIDeviceNew(vfPCIAddr->domain, vfPCIAddr->bus, - vfPCIAddr->slot, vfPCIAddr->function); - - cleanup: - VIR_FREE(vfPCIAddr); - - return vfPCIDevice; + return virPCIDeviceNew(vfPCIAddr->domain, vfPCIAddr->bus, + vfPCIAddr->slot, vfPCIAddr->function); } =20 =20 @@ -1601,12 +1595,12 @@ virNetDevSetVfConfig(const char *ifname, int vf, char macstr[VIR_MAC_STRING_BUFLEN]; struct nlmsgerr *err; unsigned int recvbuflen =3D 0; - struct nl_msg *nl_msg; struct nlattr *vfinfolist, *vfinfo; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC, .ifi_index =3D -1, }; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!macaddr && vlanid < 0) @@ -1710,7 +1704,6 @@ virNetDevSetVfConfig(const char *ifname, int vf, macaddr ? virMacAddrFormat(macaddr, macstr) : "(unchanged)", vlanid, rc < 0 ? "Fail" : "Success"); =20 - nlmsg_free(nl_msg); return rc; =20 malformed_resp: @@ -1849,12 +1842,11 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, const char *stateDir, bool saveVlan) { - int ret =3D -1; const char *pfDevName =3D NULL; virMacAddr oldMAC; char MACStr[VIR_MAC_STRING_BUFLEN]; int oldVlanTag =3D -1; - virJSONValuePtr configJSON =3D NULL; + VIR_AUTOPTR(virJSONValue) configJSON =3D NULL; VIR_AUTOFREE(char *) pfDevOrig =3D NULL; VIR_AUTOFREE(char *) vfDevOrig =3D NULL; VIR_AUTOFREE(char *) filePath =3D NULL; @@ -1866,7 +1858,7 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, =20 /* linkdev should get the VF's netdev name (or NULL if none) */ if (virNetDevPFGetVF(pfDevName, vf, &vfDevOrig) < 0) - goto cleanup; + return -1; =20 linkdev =3D vfDevOrig; saveVlan =3D true; @@ -1878,12 +1870,12 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, */ =20 if (virNetDevGetPhysicalFunction(linkdev, &pfDevOrig) < 0) - goto cleanup; + return -1; =20 pfDevName =3D pfDevOrig; =20 if (virNetDevGetVirtualFunctionIndex(pfDevName, linkdev, &vf) < 0) - goto cleanup; + return -1; } =20 if (pfDevName) { @@ -1901,7 +1893,7 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, * explicitly enable the PF in the host system network config. */ if (virNetDevGetOnline(pfDevName, &pfIsOnline) < 0) - goto cleanup; + return -1; =20 if (!pfIsOnline) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1910,12 +1902,12 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, "change host network config to put the " "PF online."), vf, pfDevName); - goto cleanup; + return -1; } } =20 if (!(configJSON =3D virJSONValueNewObject())) - goto cleanup; + return -1; =20 /* if there is a PF, it's now in pfDevName, and linkdev is either * the VF's name, or NULL (if the VF isn't bound to a net driver @@ -1924,11 +1916,11 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, =20 if (pfDevName && saveVlan) { if (virAsprintf(&filePath, "%s/%s_vf%d", stateDir, pfDevName, vf) = < 0) - goto cleanup; + return -1; =20 /* get admin MAC and vlan tag */ if (virNetDevGetVfConfig(pfDevName, vf, &oldMAC, &oldVlanTag) < 0) - goto cleanup; + return -1; =20 if (virJSONValueObjectAppendString(configJSON, VIR_NETDEV_KEYNAME_ADMIN_MAC, @@ -1936,39 +1928,36 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, virJSONValueObjectAppendNumberInt(configJSON, VIR_NETDEV_KEYNAME_VLAN_TAG, oldVlanTag) < 0) { - goto cleanup; + return -1; } =20 } else { if (virAsprintf(&filePath, "%s/%s", stateDir, linkdev) < 0) - goto cleanup; + return -1; } =20 if (linkdev) { if (virNetDevGetMAC(linkdev, &oldMAC) < 0) - goto cleanup; + return -1; =20 /* for interfaces with no pfDevName (i.e. not a VF, this will * be the only value in the file. */ if (virJSONValueObjectAppendString(configJSON, VIR_NETDEV_KEYNAME_= MAC, virMacAddrFormat(&oldMAC, MACSt= r)) < 0) - goto cleanup; + return -1; } =20 if (!(fileStr =3D virJSONValueToString(configJSON, true))) - goto cleanup; + return -1; =20 if (virFileWriteStr(filePath, fileStr, O_CREAT|O_TRUNC|O_WRONLY) < 0) { virReportSystemError(errno, _("Unable to preserve mac/vlan tag " "for device =3D %s, vf =3D %d"), lin= kdev, vf); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virJSONValueFree(configJSON); - return ret; + return 0; } =20 =20 @@ -2000,12 +1989,14 @@ virNetDevReadNetConfig(const char *linkdev, int vf, virNetDevVlanPtr *vlan, virMacAddrPtr *MAC) { - int ret =3D -1; const char *pfDevName =3D NULL; - virJSONValuePtr configJSON =3D NULL; const char *MACStr =3D NULL; const char *adminMACStr =3D NULL; int vlanTag =3D -1; + VIR_AUTOPTR(virMacAddr) tmpAdminMAC =3D NULL; + VIR_AUTOPTR(virNetDevVlan) tmpVlan =3D NULL; + VIR_AUTOPTR(virMacAddr) tmpMAC =3D NULL; + VIR_AUTOPTR(virJSONValue) configJSON =3D NULL; VIR_AUTOFREE(char *) pfDevOrig =3D NULL; VIR_AUTOFREE(char *) vfDevOrig =3D NULL; VIR_AUTOFREE(char *) filePath =3D NULL; @@ -2021,7 +2012,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, =20 /* linkdev should get the VF's netdev name (or NULL if none) */ if (virNetDevPFGetVF(pfDevName, vf, &vfDevOrig) < 0) - goto cleanup; + return -1; =20 linkdev =3D vfDevOrig; =20 @@ -2032,12 +2023,12 @@ virNetDevReadNetConfig(const char *linkdev, int vf, */ =20 if (virNetDevGetPhysicalFunction(linkdev, &pfDevOrig) < 0) - goto cleanup; + return -1; =20 pfDevName =3D pfDevOrig; =20 if (virNetDevGetVirtualFunctionIndex(pfDevName, linkdev, &vf) < 0) - goto cleanup; + return -1; } =20 /* if there is a PF, it's now in pfDevName, and linkdev is either @@ -2047,7 +2038,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, =20 if (pfDevName) { if (virAsprintf(&filePath, "%s/%s_vf%d", stateDir, pfDevName, vf) = < 0) - goto cleanup; + return -1; =20 if (linkdev && !virFileExists(filePath)) { /* the device may have been stored in a file named for the @@ -2062,19 +2053,18 @@ virNetDevReadNetConfig(const char *linkdev, int vf, =20 if (!pfDevName) { if (virAsprintf(&filePath, "%s/%s", stateDir, linkdev) < 0) - goto cleanup; + return -1; } =20 if (!virFileExists(filePath)) { /* having no file to read is not necessarily an error, so we * just return success, but with MAC, adminMAC, and vlan set to NU= LL */ - ret =3D 0; - goto cleanup; + return 0; } =20 if (virFileReadAll(filePath, 128, &fileStr) < 0) - goto cleanup; + return -1; =20 if (strchr("0123456789abcdefABCDEF", fileStr[0])) { const char *vlanStr =3D NULL; @@ -2096,7 +2086,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse vlan tag '%s' from file '%s= '"), vlanStr, filePath); - goto cleanup; + return -1; } } else { /* if there is only one line, it is MAC */ @@ -2112,7 +2102,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, _("invalid json in net device saved " "config file '%s': '%.60s'"), filePath, fileStr); - goto cleanup; + return -1; } =20 MACStr =3D virJSONValueObjectGetString(configJSON, @@ -2129,57 +2119,52 @@ virNetDevReadNetConfig(const char *linkdev, int vf, "has unexpected contents, missing both " "'MAC' and 'adminMAC': '%.60s'"), filePath, fileStr); - goto cleanup; + return -1; } } =20 if (MACStr) { - if (VIR_ALLOC(*MAC) < 0) - goto cleanup; + if (VIR_ALLOC(tmpMAC) < 0) + return -1; =20 - if (virMacAddrParse(MACStr, *MAC) < 0) { + if (virMacAddrParse(MACStr, tmpMAC) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse MAC address '%s' from file '%s'= "), MACStr, filePath); - goto cleanup; + return -1; } } =20 if (adminMACStr) { - if (VIR_ALLOC(*adminMAC) < 0) - goto cleanup; + if (VIR_ALLOC(tmpAdminMAC) < 0) + return -1; =20 - if (virMacAddrParse(adminMACStr, *adminMAC) < 0) { + if (virMacAddrParse(adminMACStr, tmpAdminMAC) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse MAC address '%s' from file '%s'= "), adminMACStr, filePath); - goto cleanup; + return -1; } } =20 if (vlanTag !=3D -1) { /* construct a simple virNetDevVlan object with a single tag */ - if (VIR_ALLOC(*vlan) < 0) - goto cleanup; - if (VIR_ALLOC((*vlan)->tag) < 0) - goto cleanup; - (*vlan)->nTags =3D 1; - (*vlan)->tag[0] =3D vlanTag; + if (VIR_ALLOC(tmpVlan) < 0) + return -1; + if (VIR_ALLOC(tmpVlan->tag) < 0) + return -1; + tmpVlan->nTags =3D 1; + tmpVlan->tag[0] =3D vlanTag; } =20 /* we won't need the file again */ ignore_value(unlink(filePath)); =20 - ret =3D 0; - cleanup: - if (ret < 0) { - VIR_FREE(*adminMAC); - VIR_FREE(*MAC); - VIR_FREE(*vlan); - } + VIR_STEAL_PTR(*adminMAC, tmpAdminMAC); + VIR_STEAL_PTR(*MAC, tmpMAC); + VIR_STEAL_PTR(*vlan, tmpVlan); =20 - virJSONValueFree(configJSON); - return ret; + return 0; } =20 =20 @@ -2208,11 +2193,10 @@ virNetDevSetNetConfig(const char *linkdev, int vf, const virMacAddr *MAC, bool setVlan) { - int ret =3D -1; char MACStr[VIR_MAC_STRING_BUFLEN]; const char *pfDevName =3D NULL; int vlanTag =3D -1; - virPCIDevicePtr vfPCIDevice =3D NULL; + VIR_AUTOPTR(virPCIDevice) vfPCIDevice =3D NULL; VIR_AUTOFREE(char *) pfDevOrig =3D NULL; VIR_AUTOFREE(char *) vfDevOrig =3D NULL; =20 @@ -2222,7 +2206,7 @@ virNetDevSetNetConfig(const char *linkdev, int vf, =20 /* linkdev should get the VF's netdev name (or NULL if none) */ if (virNetDevPFGetVF(pfDevName, vf, &vfDevOrig) < 0) - goto cleanup; + return -1; =20 linkdev =3D vfDevOrig; =20 @@ -2233,12 +2217,12 @@ virNetDevSetNetConfig(const char *linkdev, int vf, */ =20 if (virNetDevGetPhysicalFunction(linkdev, &pfDevOrig) < 0) - goto cleanup; + return -1; =20 pfDevName =3D pfDevOrig; =20 if (virNetDevGetVirtualFunctionIndex(pfDevName, linkdev, &vf) < 0) - goto cleanup; + return -1; } =20 =20 @@ -2250,14 +2234,14 @@ virNetDevSetNetConfig(const char *linkdev, int vf, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("admin MAC can only be set for SR-IOV VFs, bu= t " "%s is not a VF"), linkdev); - goto cleanup; + return -1; } =20 if (vlan) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("vlan can only be set for SR-IOV VFs, but " "%s is not a VF"), linkdev); - goto cleanup; + return -1; } =20 } else { @@ -2266,14 +2250,14 @@ virNetDevSetNetConfig(const char *linkdev, int vf, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("vlan trunking is not supported " "by SR-IOV network devices")); - goto cleanup; + return -1; } =20 if (!setVlan) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("vlan tag set for interface %s but " "caller requested it not be set")); - goto cleanup; + return -1; } =20 vlanTag =3D vlan->tag[0]; @@ -2291,7 +2275,7 @@ virNetDevSetNetConfig(const char *linkdev, int vf, _("VF %d of PF '%s' is not bound to a net drive= r, " "so its MAC address cannot be set to %s"), vf, pfDevName, virMacAddrFormat(MAC, MACStr)); - goto cleanup; + return -1; } =20 setMACrc =3D virNetDevSetMACInternal(linkdev, MAC, !!pfDevOrig); @@ -2302,7 +2286,7 @@ virNetDevSetNetConfig(const char *linkdev, int vf, /* if pfDevOrig =3D=3D NULL, this isn't a VF, so we've failed = */ if (!pfDevOrig || (errno !=3D EADDRNOTAVAIL && errno !=3D EPERM)) - goto cleanup; + return -1; =20 /* Otherwise this is a VF, and virNetDevSetMAC failed with * EADDRNOTAVAIL/EPERM, which could be due to the @@ -2316,18 +2300,18 @@ virNetDevSetNetConfig(const char *linkdev, int vf, =20 if (virNetDevSetVfConfig(pfDevName, vf, MAC, vlanTag, &allowRetry) < 0) { - goto cleanup; + return -1; } =20 /* admin MAC is set, now we need to construct a virPCIDevice * object so we can call virPCIDeviceRebind() */ if (!(vfPCIDevice =3D virNetDevGetPCIDevice(linkdev))) - goto cleanup; + return -1; =20 /* Rebind the device. This should set the proper MAC address */ if (virPCIDeviceRebind(vfPCIDevice) < 0) - goto cleanup; + return -1; =20 /* Wait until virNetDevGetIndex for the VF netdev returns succ= ess. * This indicates that the device is ready to be used. If we d= on't @@ -2379,20 +2363,17 @@ virNetDevSetNetConfig(const char *linkdev, int vf, * with the "locally administered" bit set. */ if (!allowRetry) - goto cleanup; + return -1; =20 allowRetry =3D false; if (virNetDevSetVfConfig(pfDevName, vf, &altZeroMAC, vlanTag, &allowRetry) < = 0) { - goto cleanup; + return -1; } } } =20 - ret =3D 0; - cleanup: - virPCIDeviceFree(vfPCIDevice); - return ret; + return 0; } =20 =20 @@ -2751,8 +2732,8 @@ static int virNetDevGetMcastList(const char *ifname, { char *cur =3D NULL; char *next =3D NULL; - int ret =3D -1, len; - virNetDevMcastEntryPtr entry =3D NULL; + int len; + VIR_AUTOPTR(virNetDevMcastEntry) entry =3D NULL; VIR_AUTOFREE(char *) buf =3D NULL; =20 mcast->entries =3D NULL; @@ -2760,35 +2741,31 @@ static int virNetDevGetMcastList(const char *ifname, =20 /* Read entire multicast table into memory */ if ((len =3D virFileReadAll(PROC_NET_DEV_MCAST, MAX_MCAST_SIZE, &buf))= <=3D 0) - goto cleanup; + return -1; =20 cur =3D buf; while (cur) { if (!entry && VIR_ALLOC(entry) < 0) - goto cleanup; + return -1; =20 next =3D strchr(cur, '\n'); if (next) next++; if (virNetDevParseMcast(cur, entry)) - goto cleanup; + return -1; =20 /* Only return global multicast MAC addresses for * specified interface */ if (entry->global && STREQ(ifname, entry->name)) { if (VIR_APPEND_ELEMENT(mcast->entries, mcast->nentries, entry)) - goto cleanup; + return -1; } else { memset(entry, 0, sizeof(virNetDevMcastEntry)); } cur =3D next && ((next - buf) < len) ? next : NULL; } =20 - ret =3D 0; - cleanup: - VIR_FREE(entry); - - return ret; + return 0; } =20 =20 @@ -2867,30 +2844,29 @@ virNetDevRxFilterFree(virNetDevRxFilterPtr filter) int virNetDevGetRxFilter(const char *ifname, virNetDevRxFilterPtr *filter) { - int ret =3D -1; bool receive =3D false; - virNetDevRxFilterPtr fil =3D virNetDevRxFilterNew(); + VIR_AUTOPTR(virNetDevRxFilter) fil =3D virNetDevRxFilterNew(); =20 if (!fil) - goto cleanup; + return -1; =20 if (virNetDevGetMAC(ifname, &fil->mac)) - goto cleanup; + return -1; =20 if (virNetDevGetMulticastTable(ifname, fil)) - goto cleanup; + return -1; =20 if (virNetDevGetPromiscuous(ifname, &fil->promiscuous)) - goto cleanup; + return -1; =20 if (virNetDevGetRcvAllMulti(ifname, &receive)) - goto cleanup; + return -1; =20 if (receive) { fil->multicast.mode =3D VIR_NETDEV_RX_FILTER_MODE_ALL; } else { if (virNetDevGetRcvMulti(ifname, &receive)) - goto cleanup; + return -1; =20 if (receive) fil->multicast.mode =3D VIR_NETDEV_RX_FILTER_MODE_NORMAL; @@ -2898,15 +2874,9 @@ int virNetDevGetRxFilter(const char *ifname, fil->multicast.mode =3D VIR_NETDEV_RX_FILTER_MODE_NONE; } =20 - ret =3D 0; - cleanup: - if (ret < 0) { - virNetDevRxFilterFree(fil); - fil =3D NULL; - } + VIR_STEAL_PTR(*filter, fil); =20 - *filter =3D fil; - return ret; + return 0; } =20 #if defined(SIOCETHTOOL) && defined(HAVE_STRUCT_IFREQ) @@ -3118,21 +3088,20 @@ virNetDevPutExtraHeader(struct nlmsghdr *nlh, static uint32_t virNetDevGetFamilyId(const char *family_name) { - struct nl_msg *nl_msg =3D NULL; struct genlmsghdr* gmsgh =3D NULL; struct nlattr *tb[CTRL_ATTR_MAX + 1] =3D {NULL, }; unsigned int recvbuflen; - uint32_t family_id =3D 0; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!(nl_msg =3D nlmsg_alloc_simple(GENL_ID_CTRL, NLM_F_REQUEST | NLM_F_ACK))) { virReportOOMError(); - goto cleanup; + return 0; } =20 if (!(gmsgh =3D virNetDevPutExtraHeader(nlmsg_hdr(nl_msg), sizeof(stru= ct genlmsghdr)))) - goto cleanup; + return 0; =20 gmsgh->cmd =3D CTRL_CMD_GETFAMILY; gmsgh->version =3D DEVLINK_GENL_VERSION; @@ -3140,26 +3109,22 @@ virNetDevGetFamilyId(const char *family_name) if (nla_put_string(nl_msg, CTRL_ATTR_FAMILY_NAME, family_name) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return 0; } =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0, NETLINK_GENERI= C, 0) < 0) - goto cleanup; + return 0; =20 if (nlmsg_parse(resp, sizeof(struct nlmsghdr), tb, CTRL_ATTR_MAX, NULL= ) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed netlink response message")); - goto cleanup; + return 0; } =20 if (tb[CTRL_ATTR_FAMILY_ID] =3D=3D NULL) - goto cleanup; + return 0; =20 - family_id =3D *(uint32_t *)RTA_DATA(tb[CTRL_ATTR_FAMILY_ID]); - - cleanup: - nlmsg_free(nl_msg); - return family_id; + return *(uint32_t *)RTA_DATA(tb[CTRL_ATTR_FAMILY_ID]); } =20 =20 @@ -3177,43 +3142,40 @@ static int virNetDevSwitchdevFeature(const char *ifname, virBitmapPtr *out) { - struct nl_msg *nl_msg =3D NULL; unsigned int recvbuflen; struct nlattr *tb[DEVLINK_ATTR_MAX + 1] =3D {NULL, }; - virPCIDevicePtr pci_device_ptr =3D NULL; struct genlmsghdr* gmsgh =3D NULL; const char *pci_name; int is_vf =3D -1; - int ret =3D -1; uint32_t family_id; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; + VIR_AUTOPTR(virPCIDevice) pci_device_ptr =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; VIR_AUTOFREE(char *) pfname =3D NULL; =20 if ((family_id =3D virNetDevGetFamilyId(DEVLINK_GENL_NAME)) <=3D 0) - return ret; + return -1; =20 if ((is_vf =3D virNetDevIsVirtualFunction(ifname)) < 0) - return ret; + return -1; =20 if (is_vf =3D=3D 1 && virNetDevGetPhysicalFunction(ifname, &pfname) < = 0) - goto cleanup; + return -1; =20 pci_device_ptr =3D pfname ? virNetDevGetPCIDevice(pfname) : virNetDevGetPCIDevice(ifname); /* No PCI device, then no feature bit to check/add */ - if (pci_device_ptr =3D=3D NULL) { - ret =3D 0; - goto cleanup; - } + if (pci_device_ptr =3D=3D NULL) + return 0; =20 if (!(nl_msg =3D nlmsg_alloc_simple(family_id, NLM_F_REQUEST | NLM_F_ACK))) { virReportOOMError(); - goto cleanup; + return -1; } =20 if (!(gmsgh =3D virNetDevPutExtraHeader(nlmsg_hdr(nl_msg), sizeof(stru= ct genlmsghdr)))) - goto cleanup; + return -1; =20 gmsgh->cmd =3D DEVLINK_CMD_ESWITCH_GET; gmsgh->version =3D DEVLINK_GENL_VERSION; @@ -3224,16 +3186,16 @@ virNetDevSwitchdevFeature(const char *ifname, nla_put(nl_msg, DEVLINK_ATTR_DEV_NAME, strlen(pci_name)+1, pci_nam= e) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0, NETLINK_GENERI= C, 0) < 0) - goto cleanup; + return -1; =20 if (nlmsg_parse(resp, sizeof(struct genlmsghdr), tb, DEVLINK_ATTR_MAX,= NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed netlink response message")); - goto cleanup; + return -1; } =20 if (tb[DEVLINK_ATTR_ESWITCH_MODE] && @@ -3241,12 +3203,7 @@ virNetDevSwitchdevFeature(const char *ifname, ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_SWITCHDEV)); } =20 - ret =3D 0; - - cleanup: - nlmsg_free(nl_msg); - virPCIDeviceFree(pci_device_ptr); - return ret; + return 0; } # else static int @@ -3501,8 +3458,7 @@ int virNetDevSetCoalesce(const char *ifname, int virNetDevRunEthernetScript(const char *ifname, const char *script) { - virCommandPtr cmd; - int ret; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* Not a bug! Previously we did accept script=3D"" as a NO-OP. */ if (STREQ(script, "")) @@ -3516,8 +3472,5 @@ virNetDevRunEthernetScript(const char *ifname, const = char *script) #endif virCommandAddEnvPassCommon(cmd); =20 - ret =3D virCommandRun(cmd, NULL); - - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714222560426.1679398909454; Wed, 8 Aug 2018 00:43:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA7FB12C36; Wed, 8 Aug 2018 07:43:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 70C9262929; Wed, 8 Aug 2018 07:43:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DD9533F64B; Wed, 8 Aug 2018 07:43:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787haDt005596 for ; Wed, 8 Aug 2018 03:43:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id EFB14608F4; Wed, 8 Aug 2018 07:43:36 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E46D4608F3 for ; Wed, 8 Aug 2018 07:43:36 +0000 (UTC) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 7FE8B30820D4 for ; Wed, 8 Aug 2018 07:43:35 +0000 (UTC) Received: by mail-pf1-f173.google.com with SMTP id u24-v6so700520pfn.13 for ; Wed, 08 Aug 2018 00:43:35 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=yEVPsv1tDimTuSvu4bO2zdD8A77JHQDNK3OeCvmpD9E=; b=mf6V44AUarK1BH5rGUfb9Guct7apaAAXphumlfbyCjNdYpcYUrHkv5turtDiTCMNoV sEb4H9H3Q3NvEZX88TtNO424x6cjFxDlt8Kp5HWn9FAV8UDcWlTwTTyDh6PDRomwv+kw 1oq7CwBg/XeqMNpLFdfXugdyiTfc+YmAvgvwS3nyoKIJNw8hsZbw3kIfTGVuiJwsdLQ7 U3ntuhiOwLkycRz2mdA22ZZaJY4IVcS55V7+RoOk5CMmEHE78wB1LMjZqNNW18B7ft5w dxATHbWO9fNSVakM8HZOIyG9hVjuqiyQGwHo93Cxw5Zzf/5WgVjiZ6hs2JVbEUjnnt8w ypKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=yEVPsv1tDimTuSvu4bO2zdD8A77JHQDNK3OeCvmpD9E=; b=HUD1ef0//u6dxwewXsUP48wUdPnt9Be9rnu6xoE1YkhR28u4rGpXuXbmfFyWjO765k JYn3/3gKZy9Gm+Xuv5ZV3+v4MdVuHK2om0NHfzmiqWQIw6HSVdW1O+FXa1d5nJaAt8RK EWljYeSccoqDgdlyw/PdDM//izoKVESxH4VV6r4N24Y0XYuGnYjYwTz3bpX2NsmXDHGV xobiYQNOWFcgtOE31DR1fPRg2aR/Z4T0aKp+HbOtc0oqOnYymlombuFxIrnEYxDDRAHs Fw73WUFgjdn7LhW16zt8lYwgIBGHIYxaNHy4cQ9rk119tF8OGp2Y8RRvbY7HhgOF5nAj YILQ== X-Gm-Message-State: AOUpUlHgUDc+xk0DDxmPfBHnAt11NThr4/rQs1TVetnwdwNoM5PixOkQ pfsul6rnHnv4AKdpmbT10KejcYN5 X-Google-Smtp-Source: AA+uWPyprxaxicTai2GCa2LgazikmVSiqzgRZ+Hq9z/Tkb9fQMSulc08jskGkJaOKC7CV/yT1PiwbQ== X-Received: by 2002:a63:ac57:: with SMTP id z23-v6mr1438712pgn.74.1533714214727; Wed, 08 Aug 2018 00:43:34 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:39 +0530 Message-Id: <1533501842-24503-13-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 08 Aug 2018 07:43:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 08 Aug 2018 07:43:35 +0000 (UTC) for IP:'209.85.210.173' DOMAIN:'mail-pf1-f173.google.com' HELO:'mail-pf1-f173.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.210.173 mail-pf1-f173.google.com 209.85.210.173 mail-pf1-f173.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 12/35] util: socketaddr: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:43:40 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virSocketAddrPtr is declared using VIR_AUTOPTR, the function virSocketAddrFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virsocketaddr.c | 7 ++++++- src/util/virsocketaddr.h | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 5c3bfad..6b52a3d 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -26,7 +26,6 @@ #include "virsocketaddr.h" #include "virerror.h" #include "virstring.h" -#include "viralloc.h" #include "virbuffer.h" =20 #include @@ -1253,3 +1252,9 @@ virSocketAddrPTRDomain(const virSocketAddr *addr, ret =3D -2; goto cleanup; } + +void +virSocketAddrFree(virSocketAddrPtr addr) +{ + VIR_FREE(addr); +} diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index 3029338..66f5998 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -24,14 +24,15 @@ #ifndef __VIR_SOCKETADDR_H__ # define __VIR_SOCKETADDR_H__ =20 -# include "internal.h" - # include # include # ifdef HAVE_SYS_UN_H # include # endif =20 +# include "internal.h" +# include "viralloc.h" + /* On architectures which lack these limits, define them (ie. Cygwin). * Note that the libvirt code should be robust enough to handle the * case where actual value is longer than these limits (eg. by setting @@ -162,4 +163,8 @@ int virSocketAddrPTRDomain(const virSocketAddr *addr, char **ptr) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); =20 +void virSocketAddrFree(virSocketAddrPtr addr); + +VIR_DEFINE_AUTOPTR_FUNC(virSocketAddr, virSocketAddrFree) + #endif /* __VIR_SOCKETADDR_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714225411951.5802422982815; Wed, 8 Aug 2018 00:43:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9B7A93001762; Wed, 8 Aug 2018 07:43:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61F7562531; Wed, 8 Aug 2018 07:43:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1551518037F6; Wed, 8 Aug 2018 07:43:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hfAD005622 for ; Wed, 8 Aug 2018 03:43:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC7B9308BDB3; Wed, 8 Aug 2018 07:43:41 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E3B18308BDA4 for ; Wed, 8 Aug 2018 07:43:38 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (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 E45A63082148 for ; Wed, 8 Aug 2018 07:43:37 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id p12-v6so728401pfh.2 for ; Wed, 08 Aug 2018 00:43:37 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=1ZQjjNiFRKMLdjjrlljP4yq6Fn+WqUDFw+neLV2/31A=; b=fqhEmdpovpgy5RMs6zOmCkbJgTlY/+EmQTHyRwQiv/Kc1WI3jw0qJbUgLO8tS8joVV 8b3iSOFQ/RvXVIQZ6djRnnHPO5VdzYuoUfk1Zxo6//loGJIbZMIrwxMPaXiVUn0D3bhu piIXKZBTfbgVoAgnUVKhzYBv13hGKaPE0e1XZ7nh4Z+gvG4m3AQ5WQS3OJM0mx2M7UVz JZODJnHsx2VoUqBD7z8bAdUxZRXAUkAxBnZ+x4cB5PW2JxqnJ1X/F0WYpHOuWZqp8o1Z 75vtWCWL4+6DJC0wtJGwIwcUf21/R/MXU+hx/XfjqetU3xYT2J0ei7cHwZdJu/kitFB1 j27Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=1ZQjjNiFRKMLdjjrlljP4yq6Fn+WqUDFw+neLV2/31A=; b=K0oKNDK3uStgF9DCXLxeS3Khtp+PnhC0X+dssbFqfnzVWhsdZl/awukaxk1Vbd60pe R0/zcaYXD8bpwHr/BFbtyoTf+wLjb2ocKpNBCYAqGG8yAbHEyBA5KjKW4lAo/U1G8vmb PB2qpVLAo/XCXBp/MGrwkVF8eDvFBfir4WedFO0+bob3p8p4CiQuw5s5X97QSV7N9kFT Xcfx86ZTwtCVTkHm4SG/nmKgQdJKrDvZM4Ayyi5t+dtRBs/WsrZ84mVyzvCbNs3Og4RU gYoZDSzadmwZGJ0QObbKiYHQwQ6iKg/eH4FCiVvNngcsWiDuvVwUP0Rp9dwmpNu3sJNi E4/A== X-Gm-Message-State: AOUpUlGQqG9A68quLL8GQ5SjnSwJrhv17gyORJ9htjwuvuQNsAJvTpBE DnaHhbrnfnifKUOIbeU+JmkdhdHQ X-Google-Smtp-Source: AA+uWPwrFrS3PifMX4q+80Evt41TSqckAboIWABEay4INFZ9fts879DEdsVRnxc/rY80CouOV9czLw== X-Received: by 2002:a63:fd52:: with SMTP id m18-v6mr1464361pgj.304.1533714217094; Wed, 08 Aug 2018 00:43:37 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:40 +0530 Message-Id: <1533501842-24503-14-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 08 Aug 2018 07:43:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 08 Aug 2018 07:43:38 +0000 (UTC) for IP:'209.85.210.196' DOMAIN:'mail-pf1-f196.google.com' HELO:'mail-pf1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.210.196 mail-pf1-f196.google.com 209.85.210.196 mail-pf1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 13/35] util: socketaddr: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 08 Aug 2018 07:43:44 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virsocketaddr.c | 70 ++++++++++++++++++++------------------------= ---- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 6b52a3d..eee725d 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -432,10 +432,10 @@ virSocketAddrFormatFull(const virSocketAddr *addr, if (withService) { if (virAsprintf(&addrstr, VIR_LOOPBACK_IPV4_ADDR"%s0", separator ? separator : ":") < 0) - goto error; + return NULL; } else { if (VIR_STRDUP(addrstr, VIR_LOOPBACK_IPV4_ADDR) < 0) - goto error; + return NULL; } return addrstr; } @@ -452,33 +452,27 @@ virSocketAddrFormatFull(const virSocketAddr *addr, } =20 if (withService) { - char *ipv6_host =3D NULL; + VIR_AUTOFREE(char *) ipv6_host =3D NULL; /* sasl_new_client demands the socket address to be in an odd form= at: * a.b.c.d;port or e:f:g:h:i:j:k:l;port, so use square brackets for * IPv6 only if no separator is passed to the function */ if (!separator && VIR_SOCKET_ADDR_FAMILY(addr) =3D=3D AF_INET6) { if (virAsprintf(&ipv6_host, "[%s]", host) < 0) - goto error; + return NULL; } =20 if (virAsprintf(&addrstr, "%s%s%s", ipv6_host ? ipv6_host : host, separator ? separator : ":", port) =3D=3D -1) { - VIR_FREE(ipv6_host); - goto error; + return NULL; } - - VIR_FREE(ipv6_host); } else { if (VIR_STRDUP(addrstr, host) < 0) - goto error; + return NULL; } =20 return addrstr; - - error: - return NULL; } =20 =20 @@ -759,24 +753,26 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSock= etAddrPtr end, int ret =3D 0; size_t i; virSocketAddr netmask; - char *startStr =3D NULL, *endStr =3D NULL, *netStr =3D NULL; + VIR_AUTOFREE(char *) startStr =3D NULL; + VIR_AUTOFREE(char *) endStr =3D NULL; + VIR_AUTOFREE(char *) netStr =3D NULL; =20 if (start =3D=3D NULL || end =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("NULL argument - %p %p"), start, end); - goto error; + return -1; } =20 startStr =3D virSocketAddrFormat(start); endStr =3D virSocketAddrFormat(end); if (!startStr || !endStr) - goto error; /*error already reported */ + return -1; /*error already reported */ =20 if (VIR_SOCKET_ADDR_FAMILY(start) !=3D VIR_SOCKET_ADDR_FAMILY(end)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("mismatch of address family in range %s - %s"), startStr, endStr); - goto error; + return -1; } =20 if (network) { @@ -784,14 +780,14 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSock= etAddrPtr end, * network the range should be within */ if (!(netStr =3D virSocketAddrFormat(network))) - goto error; + return -1; =20 if (VIR_SOCKET_ADDR_FAMILY(start) !=3D VIR_SOCKET_ADDR_FAMILY(netw= ork)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("mismatch of address family in " "range %s - %s for network %s"), startStr, endStr, netStr); - goto error; + return -1; } =20 if (prefix < 0 || @@ -801,7 +797,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("bad prefix %d for network %s when " " checking range %s - %s"), prefix, netStr, startStr, endStr); - goto error; + return -1; } =20 /* both start and end of range need to be within network */ @@ -811,7 +807,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("range %s - %s is not entirely within " "network %s/%d"), startStr, endStr, netStr, prefix); - goto error; + return -1; } =20 if (VIR_SOCKET_ADDR_IS_FAMILY(start, AF_INET)) { @@ -823,7 +819,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("failed to construct broadcast or network= " "address for network %s/%d"), netStr, prefix); - goto error; + return -1; } =20 /* Don't allow the start of the range to be the network @@ -838,7 +834,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("start of range %s - %s in network %s/%d " "is the network address"), startStr, endStr, netStr, prefix); - goto error; + return -1; } =20 if (virSocketAddrEqual(end, &broadcast)) { @@ -846,7 +842,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("end of range %s - %s in network %s/%d " "is the broadcast address"), startStr, endStr, netStr, prefix); - goto error; + return -1; } } } @@ -860,7 +856,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("failed to get IPv4 address " "for start or end of range %s - %s"), startStr, endStr); - goto error; + return -1; } =20 /* legacy check that everything except the last two bytes @@ -868,10 +864,10 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSock= etAddrPtr end, */ for (i =3D 0; i < 2; i++) { if (t1[i] !=3D t2[i]) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("range %s - %s is too large (> 65535)"), - startStr, endStr); - goto error; + virReportError(VIR_ERR_INTERNAL_ERROR, + _("range %s - %s is too large (> 65535)"), + startStr, endStr); + return -1; } } ret =3D (t2[2] - t1[2]) * 256 + (t2[3] - t1[3]); @@ -879,7 +875,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, virReportError(VIR_ERR_INTERNAL_ERROR, _("range %s - %s is reversed "), startStr, endStr); - goto error; + return -1; } ret++; } else if (VIR_SOCKET_ADDR_IS_FAMILY(start, AF_INET6)) { @@ -891,7 +887,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("failed to get IPv6 address " "for start or end of range %s - %s"), startStr, endStr); - goto error; + return -1; } =20 /* legacy check that everything except the last two bytes are @@ -902,7 +898,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, virReportError(VIR_ERR_INTERNAL_ERROR, _("range %s - %s is too large (> 65535)"), startStr, endStr); - goto error; + return -1; } } ret =3D t2[7] - t1[7]; @@ -910,7 +906,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, virReportError(VIR_ERR_INTERNAL_ERROR, _("range %s - %s start larger than end"), startStr, endStr); - goto error; + return -1; } ret++; } else { @@ -918,18 +914,10 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSock= etAddrPtr end, _("unsupported address family " "for range %s - %s, must be ipv4 or ipv6"), startStr, endStr); - goto error; + return -1; } =20 - cleanup: - VIR_FREE(startStr); - VIR_FREE(endStr); - VIR_FREE(netStr); return ret; - - error: - ret =3D -1; - goto cleanup; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714234126825.4295298321653; Wed, 8 Aug 2018 00:43:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1812F308FBA5; Wed, 8 Aug 2018 07:43:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C6502608F4; Wed, 8 Aug 2018 07:43:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7C62118037F7; Wed, 8 Aug 2018 07:43:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hiCq005648 for ; Wed, 8 Aug 2018 03:43:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 238CB277D0; Wed, 8 Aug 2018 07:43:44 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B7AB277D5 for ; Wed, 8 Aug 2018 07:43:41 +0000 (UTC) Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 A187D4DB12 for ; Wed, 8 Aug 2018 07:43:40 +0000 (UTC) Received: by mail-pg1-f181.google.com with SMTP id h12-v6so696207pgs.3 for ; Wed, 08 Aug 2018 00:43:40 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=3CNIRrnTS2BtaiH4wEgPHVdpmkN9OAt5wxYFao4cwdM=; b=YYQIISfL9SAwugarQfMtBSjedpKWx21U+mh3sunaCzc1GJIXkPfIu/9b+ON0GcT1EJ 40V4tYJJQfH+cS4VhQdPlzxyfPVUTdtrq+NevJrTIxNiik14SSCvC67/scPEpxM+yl6L 8aBKLpuWYZZ8JdYMXo4jIpqwmOEYhbX5cJ2JH+q5L/e8WCX0L0FKF1O7C16v2snUsrxw ndKMlkqKnq5gaDRagF+KnJIO+hUk8X9QP1TvUqTq7lu+ZwQGsti3o6U6hkbfGriTt/2R nK+kTX15SKbuNbVLqyL12gTC29WJRT+193ELpNQyckKsJMjS3ltk3BZR9uCA2gOalWWT aZFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=3CNIRrnTS2BtaiH4wEgPHVdpmkN9OAt5wxYFao4cwdM=; b=g0nMl7GG8/HiWs0e9t46FPFl6fcCZ93eNwJGwNYZEI21IZ5N2fCCk3kO6Wacdno0vJ UkI6nacvXH+OUoTmGB41mMGVkcUw3c06aHLpsudVy0Nq0DsZGJ24KC+hpJMiQp0VK0Mn 3gYloxLwslgzpI7xHgssBC9yAaVo5/Q/x5oKLbMYmbyeVmxCWwP3tGnZT/qNv/L018Ny xv7ZR5Pay6GEl6KFnhWsdaSrzCN2rrSNtD+tlwKm+fXedqStzTvj7n2dCw89xDHUFL2u fGD2oNdmRF/cG1zF2Srr2PYajCvWdAEHXZFy5lgKcsW6zWH8QTr/Dg1T60TQ7rb5oeVo zIiQ== X-Gm-Message-State: AOUpUlFfaxw/P/nA6JfH/7bTuFbi354T7dVGK964o7WKxm56ZkIf4ou5 tgGeh5D2HgFyYeQ9QFRltXOJRoXX X-Google-Smtp-Source: AA+uWPyVntSHWE+QBdQRwDtwyorSwfu07r6Xgd/K2UksiITfJT/tF25eHaSju+Uoerc0HP5+8YtAUA== X-Received: by 2002:a63:d5b:: with SMTP id 27-v6mr1422771pgn.107.1533714219888; Wed, 08 Aug 2018 00:43:39 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:41 +0530 Message-Id: <1533501842-24503-15-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 08 Aug 2018 07:43:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 08 Aug 2018 07:43:40 +0000 (UTC) for IP:'209.85.215.181' DOMAIN:'mail-pg1-f181.google.com' HELO:'mail-pg1-f181.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.215.181 mail-pg1-f181.google.com 209.85.215.181 mail-pg1-f181.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 14/35] util: socketaddr: use VIR_AUTOPTR for aggregate types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 08 Aug 2018 07:43:52 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virsocketaddr.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index eee725d..3e5ea64 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -1193,52 +1193,46 @@ virSocketAddrPTRDomain(const virSocketAddr *addr, unsigned int prefix, char **ptr) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; size_t i; - int ret =3D -1; + VIR_AUTOPTR(virBuffer) buf =3D NULL; + + if (VIR_ALLOC(buf) < 0) + return -1; =20 if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET)) { virSocketAddrIPv4 ip; =20 if (prefix =3D=3D 0 || prefix >=3D 32 || prefix % 8 !=3D 0) - goto unsupported; + return -2; =20 if (virSocketAddrGetIPv4Addr(addr, &ip) < 0) - goto cleanup; + return -1; =20 for (i =3D prefix / 8; i > 0; i--) - virBufferAsprintf(&buf, "%u.", ip[i - 1]); + virBufferAsprintf(buf, "%u.", ip[i - 1]); =20 - virBufferAddLit(&buf, VIR_SOCKET_ADDR_IPV4_ARPA); + virBufferAddLit(buf, VIR_SOCKET_ADDR_IPV4_ARPA); } else if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET6)) { virSocketAddrIPv6Nibbles ip; =20 if (prefix =3D=3D 0 || prefix >=3D 128 || prefix % 4 !=3D 0) - goto unsupported; + return -2; =20 if (virSocketAddrGetIPv6Nibbles(addr, &ip) < 0) - goto cleanup; + return -1; =20 for (i =3D prefix / 4; i > 0; i--) - virBufferAsprintf(&buf, "%x.", ip[i - 1]); + virBufferAsprintf(buf, "%x.", ip[i - 1]); =20 - virBufferAddLit(&buf, VIR_SOCKET_ADDR_IPV6_ARPA); + virBufferAddLit(buf, VIR_SOCKET_ADDR_IPV6_ARPA); } else { - goto unsupported; + return -2; } =20 - if (!(*ptr =3D virBufferContentAndReset(&buf))) - goto cleanup; + if (!(*ptr =3D virBufferContentAndReset(buf))) + return -1; =20 - ret =3D 0; - - cleanup: - virBufferFreeAndReset(&buf); - return ret; - - unsupported: - ret =3D -2; - goto cleanup; + return 0; } =20 void --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714239695732.9166396690637; Wed, 8 Aug 2018 00:43:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A296B308226A; Wed, 8 Aug 2018 07:43:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 440CA62534; Wed, 8 Aug 2018 07:43:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DF1F618037FD; Wed, 8 Aug 2018 07:43:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hlDX005692 for ; Wed, 8 Aug 2018 03:43:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id F192420156A3; Wed, 8 Aug 2018 07:43:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E4C8B20156A1 for ; Wed, 8 Aug 2018 07:43:43 +0000 (UTC) Received: from mail-pl0-f53.google.com (mail-pl0-f53.google.com [209.85.160.53]) (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 DF14330E6859 for ; Wed, 8 Aug 2018 07:43:42 +0000 (UTC) Received: by mail-pl0-f53.google.com with SMTP id j8-v6so648552pll.12 for ; Wed, 08 Aug 2018 00:43:42 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=SCjzFJqmECuJ346FslrFdSwyW2WEEc/mshR5OxD2/98=; b=ZrJBT1aU3H7W9SzrAvnFh0a4Vvb0NgjfL3THemR70yXVCJNalwtZF4+xzv6m3CFtGM OyUWw1r2h8PSnLtDyRRFZ6WHKp9jBoZwcJS5zanMpo3zSuI7uCqswBtK5G31BSv5chf6 adw0ppbMGluV78AvPpmQrOwdQWmxNb89RRkYwuFoI5SivQ0AsR1Yqi78zcXNF0QZQtWJ NH13O4o8+i7AzuqVjTOXcTQVBp2DAz42JdJX5l4xWdofXAclhNquh1SW/Xdp71To3PsV 9Y1bzNSJaQbzW8/UdFu5qe9xSKqJxIcZZr4azelCP3MAw0FWHn+wpkSiC0g1dzGw6gh4 TMKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=SCjzFJqmECuJ346FslrFdSwyW2WEEc/mshR5OxD2/98=; b=WiqIT0jgscnV2PTivtuu5PBWxve4Hvg5ItEDBfhj4BmSLGgo16mMJHCbnsSJ7/16h2 jIzewZh8LcKS2rsi/FvTf7PvctUwrG1jsFvu+307fpSqqCZKAhRw6ZK+8HvKSccCc3TE vRnr75B2zvQ8vhgx47ooaAN/jNgxzTN5tJgGCTKOi/Tih5yH2Wo3IGq6GaHZ75enVxwA VMXU1poVB3ibH8r60vFv0bddYYJQHjrGmxVi+LUP44BPZ4Id360j6Fh/cevjzrgq7KEJ n+CiwJJJQNssrx1D3msraVl3c8uMklt6PYpisOTCWnWotcxaq1dT/Tj/aKyBvqgb9TSO k+jg== X-Gm-Message-State: AOUpUlGwXNhNVoFfgByvlLzmVGxt/Qv9o1dTkJCI5x6w4tAwAHRh2pGb oF8hEybkzZMw9lctTuJBP0mLz07Y X-Google-Smtp-Source: AA+uWPwnACgwpnqgPv70fLHYRhx219ijzmpGHZ248NxfJ2kQo++HVByR4qYMgrgpa+x12Em07w4ImQ== X-Received: by 2002:a17:902:26c:: with SMTP id 99-v6mr1453506plc.341.1533714222084; Wed, 08 Aug 2018 00:43:42 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:42 +0530 Message-Id: <1533501842-24503-16-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 08 Aug 2018 07:43:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 08 Aug 2018 07:43:42 +0000 (UTC) for IP:'209.85.160.53' DOMAIN:'mail-pl0-f53.google.com' HELO:'mail-pl0-f53.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.160.53 mail-pl0-f53.google.com 209.85.160.53 mail-pl0-f53.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 15/35] util: netdevip: define virNetDevIPAddrFree for use with cleanup macros 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 08 Aug 2018 07:43:58 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Define a free function for virNetDevIPAddrPtr type for consistency and extensibility. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevip.c | 6 ++++++ src/util/virnetdevip.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index bf98ed8..7197d07 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -1129,3 +1129,9 @@ virNetDevIPInfoAddToDev(const char *ifname, cleanup: return ret; } + +void +virNetDevIPAddrFree(virNetDevIPAddrPtr ip) +{ + VIR_FREE(ip); +} diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h index 6b509ea..dfc978d 100644 --- a/src/util/virnetdevip.h +++ b/src/util/virnetdevip.h @@ -84,6 +84,7 @@ int virNetDevIPAddrGet(const char *ifname, virSocketAddrP= tr addr) int virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_t count) ATTRIBUTE_NONNULL(1); bool virNetDevIPCheckIPv6Forwarding(void); +void virNetDevIPAddrFree(virNetDevIPAddrPtr ip); =20 /* virNetDevIPRoute object */ void virNetDevIPRouteFree(virNetDevIPRoutePtr def); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714230276451.4605105287782; Wed, 8 Aug 2018 00:43:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5478A307C94E; Wed, 8 Aug 2018 07:43:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 17A67308BDB5; Wed, 8 Aug 2018 07:43:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C2E2A264FB; Wed, 8 Aug 2018 07:43:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hkdi005681 for ; Wed, 8 Aug 2018 03:43:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0AAA41001F45; Wed, 8 Aug 2018 07:43:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0361A1001938 for ; Wed, 8 Aug 2018 07:43:45 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.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 071D321BAA for ; Wed, 8 Aug 2018 07:43:45 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id w10-v6so698392pgv.2 for ; Wed, 08 Aug 2018 00:43:44 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=R5r6wcHsGpqL/nYPPN7eYa0W8JPHi9YDaJqiPvezCX4=; b=XnOLw7eh7L1r1+tRMZtPbtZK/KiPVZKZqS3wEIaObTQZSVNvYOgsSwP17LqbKZEves FIBgXIR/3z98LyhgDT9fV3Pky657CahXWemz42AWIIV+BLFNnKvCkQloj5PYv6FIt2wh pagSX0LmSvy4LgKruWX58myRge0P7FP2jiSHZt06q9ihFN5wuwVj/MmW+USGPAy0wLHY tbjuBAIZle9YeMzR8ROLUpRlwamodJrxwdTsnKxa+a+34F7kQSEta30qYMGJwKRkcO/Z Kpbx+yVe0JZrUZ2KIhSv28PgoFj0Kc0TS1FfP864AwIJcAMJqG0B1q3KrNgjXbDpugn4 9GTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=R5r6wcHsGpqL/nYPPN7eYa0W8JPHi9YDaJqiPvezCX4=; b=aW2ljclqpo+KlDTOwL6YQMqIG+0QUOkLKetGBtcm7axI6DE6bmXM5Gbx8KroZJNPSS iKHgERZSIuLvcwdsgexRAv0j8S6wL5MZFDe7t5TNWNME6IawN0pCl9ZvBtwSMsl1J/RP Rt0WXj0+m2oOrHJM6JG1DPIO6ZMGk/QIEtghQrLAzw6sx/zYYBBqoJQiClUn1TopBh3J myzfz3SJ3HLaC7m7JfnqvCGsnKOXWh3Vf3d4qyQtu4+y0OMp/DLdNOauKyW4/jaPFcVG rySBzZsEchcCr8EmKBcb1PX/iXMBUB8ex7zH/aIq8DzqvxRVmyjTeMZWqTaHM29Yg63t PElg== X-Gm-Message-State: AOUpUlGjcMVN8n4QIeG7iiWurSp2+1287qKdNIceVO5/VNUE4nMWhTbP S5lNt4ZTV9CRb+C6xM+8lfjyy+V8 X-Google-Smtp-Source: AA+uWPxsFbu+50AT+dxc6cSLHEkTb3NNSWehVzTcjEPJ6baCwhqvOUN5n97w5RoF0uzlcda1wX94Uw== X-Received: by 2002:a62:6003:: with SMTP id u3-v6mr1734458pfb.114.1533714224263; Wed, 08 Aug 2018 00:43:44 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:43 +0530 Message-Id: <1533501842-24503-17-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 08 Aug 2018 07:43:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 08 Aug 2018 07:43:45 +0000 (UTC) for IP:'209.85.215.194' DOMAIN:'mail-pg1-f194.google.com' HELO:'mail-pg1-f194.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.215.194 mail-pg1-f194.google.com 209.85.215.194 mail-pg1-f194.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 16/35] util: netdevip: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 08 Aug 2018 07:43:49 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When variables of type virNetDevIPAddrPtr and virNetDevIPRoutePtr are declared using VIR_AUTOPTR, the functions virNetDevIPAddrFree and virNetDevIPRouteFree, respectively, will be run automatically on them when they go out of scope. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevip.c | 1 - src/util/virnetdevip.h | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index 7197d07..fdb0b74 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -27,7 +27,6 @@ #include "virnetlink.h" #include "virfile.h" #include "virerror.h" -#include "viralloc.h" #include "virlog.h" #include "virstring.h" #include "virutil.h" diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h index dfc978d..9cfd27c 100644 --- a/src/util/virnetdevip.h +++ b/src/util/virnetdevip.h @@ -24,6 +24,7 @@ # define __VIR_NETDEVIP_H__ =20 # include "virsocketaddr.h" +# include "viralloc.h" =20 typedef struct _virNetDevIPAddr virNetDevIPAddr; typedef virNetDevIPAddr *virNetDevIPAddrPtr; @@ -98,4 +99,7 @@ void virNetDevIPInfoClear(virNetDevIPInfoPtr ip); int virNetDevIPInfoAddToDev(const char *ifname, virNetDevIPInfo const *ipInfo); =20 +VIR_DEFINE_AUTOPTR_FUNC(virNetDevIPAddr, virNetDevIPAddrFree) +VIR_DEFINE_AUTOPTR_FUNC(virNetDevIPRoute, virNetDevIPRouteFree) + #endif /* __VIR_NETDEVIP_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714241783570.2305455710685; Wed, 8 Aug 2018 00:44:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A81F530E6864; Wed, 8 Aug 2018 07:43:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7155B1891B; Wed, 8 Aug 2018 07:43:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0F45418037FF; Wed, 8 Aug 2018 07:43:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hvwx005777 for ; Wed, 8 Aug 2018 03:43:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id E2A393819A; Wed, 8 Aug 2018 07:43:57 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9DD438194 for ; Wed, 8 Aug 2018 07:43:48 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.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 A24A33081244 for ; Wed, 8 Aug 2018 07:43:47 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id a11-v6so688186pgw.6 for ; Wed, 08 Aug 2018 00:43:47 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=Nfv+8bIZn5BxRxi4achS9n/DhdGVuNEon0586fZHaos=; b=fSlfAKMPE/+rCPnQ8eqoRZLadzMzzxaOuZsyLZ1RMV+JbY37VIxgNtj0lWEMgwFl7b 5QHz+U7egX+rqywk5y2pop2RB+BDQKThgHzwdVpVaWkicjuhUbHrci0d095nYyGIuD9p ki2ozJoPRt5jP0C0Te29FLtAa5bT1vdtqB+LrjQFeT5rfCAo0mK/qolM6kXF0EZ70jgk NNFEPp4JnOr4LG/q2+FTw5ejMoxwos4D+d+Cqax8kuBJ5BUagJsTQv7ALrvheCcUMyLB P0423u4UwPOn5dIB9376nqku0gLPbY7ckNnmrbeKiH4dSG+so3eBeJPry92AOGV2VH2w cbAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Nfv+8bIZn5BxRxi4achS9n/DhdGVuNEon0586fZHaos=; b=Ag4kmkgwREgaSGYUDP/qUp244sELBqpRZ2sBCnYucGjwsm37T+x5T4UbHng1Xd6CTC RqAgM/z76r+TWRvRASRGlJEN4wJ9Aot1/c+fnjXbAuDGnNEOp+VTEu7XW7Qy9S0Ayc/n lIALIxER9UL4hg8uCSwCgtiSAIk69o/2+PI3txOm7lpZz21rbzkoVc5id6ntUyTA4MUe R2u35JCUcU0VvwOqfEezZuV6DHGVkkIbQ/OkslXQHQoh1cLTBg0onU7oe0mjnY+zplHU PaGmY9JqR2odON+GqzKgw4bDOY3Y54ewFzxjw2iDCvTmRu4tjm5CO/s1vmcDVyu7DI/C 0H5g== X-Gm-Message-State: AOUpUlFhPuOauuMNKSv6Mh5ParWouiamDD5z1o2h8ug4kKJvIOYxv+B5 aEWcAAo549F365PnX0TFEHIhN/pT X-Google-Smtp-Source: AA+uWPzSzxmOLXhxi8ewoZFR5iSMPMluEsHmv8HdIa2gef09O0wle6qmEcB56zGVX4T4f1u6bMDTEA== X-Received: by 2002:a63:9e0a:: with SMTP id s10-v6mr1444765pgd.326.1533714226879; Wed, 08 Aug 2018 00:43:46 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:44 +0530 Message-Id: <1533501842-24503-18-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 08 Aug 2018 07:43:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 08 Aug 2018 07:43:47 +0000 (UTC) for IP:'209.85.215.194' DOMAIN:'mail-pg1-f194.google.com' HELO:'mail-pg1-f194.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.215.194 mail-pg1-f194.google.com 209.85.215.194 mail-pg1-f194.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 17/35] util: netdevip: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 08 Aug 2018 07:44:00 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevip.c | 97 ++++++++++++++++++----------------------------= ---- 1 file changed, 34 insertions(+), 63 deletions(-) diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index fdb0b74..78c6dcf 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -171,11 +171,11 @@ virNetDevIPAddrAdd(const char *ifname, virSocketAddr *broadcast =3D NULL; int ret =3D -1; struct nl_msg *nlmsg =3D NULL; - struct nlmsghdr *resp =3D NULL; unsigned int recvbuflen; - char *ipStr =3D NULL; - char *peerStr =3D NULL; - char *bcastStr =3D NULL; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + VIR_AUTOFREE(char *) ipStr =3D NULL; + VIR_AUTOFREE(char *) peerStr =3D NULL; + VIR_AUTOFREE(char *) bcastStr =3D NULL; =20 ipStr =3D virSocketAddrFormat(addr); if (peer && VIR_SOCKET_ADDR_VALID(peer)) @@ -225,11 +225,7 @@ virNetDevIPAddrAdd(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(ipStr); - VIR_FREE(peerStr); - VIR_FREE(bcastStr); nlmsg_free(nlmsg); - VIR_FREE(resp); VIR_FREE(broadcast); return ret; } @@ -252,8 +248,8 @@ virNetDevIPAddrDel(const char *ifname, { int ret =3D -1; struct nl_msg *nlmsg =3D NULL; - struct nlmsghdr *resp =3D NULL; unsigned int recvbuflen; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!(nlmsg =3D virNetDevCreateNetlinkAddressMessage(RTM_DELADDR, ifna= me, addr, prefix, @@ -273,7 +269,6 @@ virNetDevIPAddrDel(const char *ifname, ret =3D 0; cleanup: nlmsg_free(nlmsg); - VIR_FREE(resp); return ret; } =20 @@ -309,8 +304,8 @@ virNetDevIPRouteAdd(const char *ifname, int errCode; virSocketAddr defaultAddr; virSocketAddrPtr actualAddr; - char *toStr =3D NULL; - char *viaStr =3D NULL; + VIR_AUTOFREE(char *) toStr =3D NULL; + VIR_AUTOFREE(char *) viaStr =3D NULL; =20 actualAddr =3D addr; =20 @@ -383,8 +378,6 @@ virNetDevIPRouteAdd(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(toStr); - VIR_FREE(viaStr); nlmsg_free(nlmsg); return ret; =20 @@ -452,7 +445,6 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_= t count) { struct nl_msg *nlmsg =3D NULL; struct ifaddrmsg ifa; - struct nlmsghdr *resp =3D NULL; unsigned int recvbuflen; int ret =3D -1; bool dad =3D true; @@ -475,6 +467,8 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_= t count) =20 /* Periodically query netlink until DAD finishes on all known addresse= s. */ while (dad && time(NULL) < max_time) { + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) goto cleanup; @@ -489,8 +483,6 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_= t count) dad =3D virNetDevIPParseDadStatus(resp, recvbuflen, addrs, count); if (dad) usleep(1000 * 10); - - VIR_FREE(resp); } /* Check timeout. */ if (dad) { @@ -502,7 +494,6 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_= t count) } =20 cleanup: - VIR_FREE(resp); nlmsg_free(nlmsg); return ret; } @@ -510,22 +501,18 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, siz= e_t count) static int virNetDevIPGetAcceptRA(const char *ifname) { - char *path =3D NULL; - char *buf =3D NULL; char *suffix; int accept_ra =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (virAsprintf(&path, "/proc/sys/net/ipv6/conf/%s/accept_ra", ifname ? ifname : "all") < 0) - goto cleanup; + return -1; =20 if ((virFileReadAll(path, 512, &buf) < 0) || (virStrToLong_i(buf, &suffix, 10, &accept_ra) < 0)) - goto cleanup; - - cleanup: - VIR_FREE(path); - VIR_FREE(buf); + return accept_ra; =20 return accept_ra; } @@ -545,17 +532,16 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct n= lmsghdr *resp, struct rtmsg *rtmsg =3D NLMSG_DATA(resp); int accept_ra =3D -1; struct rtattr *rta; - char *ifname =3D NULL; struct virNetDevIPCheckIPv6ForwardingData *data =3D opaque; - int ret =3D 0; int len =3D RTM_PAYLOAD(resp); int oif =3D -1; size_t i; bool hasDevice; + VIR_AUTOFREE(char *) ifname =3D NULL; =20 /* Ignore messages other than route ones */ if (resp->nlmsg_type !=3D RTM_NEWROUTE) - return ret; + return 0; =20 /* Extract a device ID attribute */ VIR_WARNINGS_NO_CAST_ALIGN @@ -566,21 +552,20 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct n= lmsghdr *resp, =20 /* Should never happen: netlink message would be broken */ if (ifname) { - char *ifname2 =3D virNetDevGetName(oif); + VIR_AUTOFREE(char *) ifname2 =3D virNetDevGetName(oif); VIR_WARN("Single route has unexpected 2nd interface " "- '%s' and '%s'", ifname, ifname2); - VIR_FREE(ifname2); break; } =20 if (!(ifname =3D virNetDevGetName(oif))) - goto error; + return -1; } } =20 /* No need to do anything else for non RA routes */ if (rtmsg->rtm_protocol !=3D RTPROT_RA) - goto cleanup; + return 0; =20 data->hasRARoutes =3D true; =20 @@ -595,15 +580,9 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nl= msghdr *resp, } if (accept_ra !=3D 2 && !hasDevice && VIR_APPEND_ELEMENT(data->devices, data->ndevices, ifname) < 0) - goto error; + return -1; =20 - cleanup: - VIR_FREE(ifname); - return ret; - - error: - ret =3D -1; - goto cleanup; + return 0; } =20 bool @@ -687,9 +666,11 @@ virNetDevIPAddrAdd(const char *ifname, unsigned int prefix) { virCommandPtr cmd =3D NULL; - char *addrstr =3D NULL, *bcaststr =3D NULL, *peerstr =3D NULL; virSocketAddr broadcast; int ret =3D -1; + VIR_AUTOFREE(char *) addrstr =3D NULL; + VIR_AUTOFREE(char *) bcaststr =3D NULL; + VIR_AUTOFREE(char *) peerstr =3D NULL; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) goto cleanup; @@ -733,9 +714,6 @@ virNetDevIPAddrAdd(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(addrstr); - VIR_FREE(bcaststr); - VIR_FREE(peerstr); virCommandFree(cmd); return ret; } @@ -747,8 +725,8 @@ virNetDevIPAddrDel(const char *ifname, unsigned int prefix) { virCommandPtr cmd =3D NULL; - char *addrstr; int ret =3D -1; + VIR_AUTOFREE(char *) addrstr =3D NULL; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) goto cleanup; @@ -773,7 +751,6 @@ virNetDevIPAddrDel(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(addrstr); virCommandFree(cmd); return ret; } @@ -786,9 +763,10 @@ virNetDevIPRouteAdd(const char *ifname, virSocketAddrPtr gateway, unsigned int metric) { - virCommandPtr cmd =3D NULL; - char *addrstr =3D NULL, *gatewaystr =3D NULL; int ret =3D -1; + virCommandPtr cmd =3D NULL; + VIR_AUTOFREE(char *) addrstr =3D NULL; + VIR_AUTOFREE(char *) gatewaystr =3D NULL; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) goto cleanup; @@ -806,8 +784,6 @@ virNetDevIPRouteAdd(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(addrstr); - VIR_FREE(gatewaystr); virCommandFree(cmd); return ret; } @@ -1083,7 +1059,6 @@ int virNetDevIPInfoAddToDev(const char *ifname, virNetDevIPInfo const *ipInfo) { - int ret =3D -1; size_t i; int prefix; =20 @@ -1093,16 +1068,15 @@ virNetDevIPInfoAddToDev(const char *ifname, =20 if ((prefix =3D virSocketAddrGetIPPrefix(&ip->address, NULL, ip->prefix)) < 0) { - char *ipStr =3D virSocketAddrFormat(&ip->address); + VIR_AUTOFREE(char *) ipStr =3D virSocketAddrFormat(&ip->addres= s); =20 virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to determine prefix for IP address '%= s'"), NULLSTR(ipStr)); - VIR_FREE(ipStr); - goto cleanup; + return -1; } if (virNetDevIPAddrAdd(ifname, &ip->address, &ip->peer, prefix) < = 0) - goto cleanup; + return -1; } =20 /* add all routes */ @@ -1110,23 +1084,20 @@ virNetDevIPInfoAddToDev(const char *ifname, virNetDevIPRoutePtr route =3D ipInfo->routes[i]; =20 if ((prefix =3D virNetDevIPRouteGetPrefix(route)) < 0) { - char *ipStr =3D virSocketAddrFormat(&route->address); + VIR_AUTOFREE(char *) ipStr =3D virSocketAddrFormat(&route->add= ress); =20 virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to determine prefix for route with de= stination '%s'"), NULLSTR(ipStr)); - VIR_FREE(ipStr); - goto cleanup; + return -1; } if (virNetDevIPRouteAdd(ifname, &route->address, prefix, &route->gateway, virNetDevIPRouteGetMetric(route)) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 void --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714265328126.41563482438448; Wed, 8 Aug 2018 00:44:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7276C80F6B; Wed, 8 Aug 2018 07:44:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 372162010D0B; Wed, 8 Aug 2018 07:44:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C5E5424F13; Wed, 8 Aug 2018 07:44:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.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 w787iDOr005903 for ; Wed, 8 Aug 2018 03:44:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id D46AB3001A67; Wed, 8 Aug 2018 07:44:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA589308332F for ; Wed, 8 Aug 2018 07:43:51 +0000 (UTC) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) (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 07F125D5EE for ; Wed, 8 Aug 2018 07:43:50 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id k19-v6so729105pfi.1 for ; Wed, 08 Aug 2018 00:43:49 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=bz41Ul1hCF7wExgBnnf68LTu5yY/XJDD/h9+93rz1sg=; b=UwWAO/Oi29BtuXfzB4Pf4n7g1+5oSk3jjcJrUR76mk3/h5n1aLgLEyYABKSz6HSiDW dJvaA/YlxmWgkJJiOVxWUv6JGjWxmfdXCo7ugF9OPGnRCISiKdso1KPzuunXWW3idIUJ I17SunqIAOJqlU2aaCbDRaX0Y6QoM3r55GCP56gF1WNDMLOz7LjebZQ5bVyunvZwdr2R x2y6bipGcn+jlu6trVjECsHzFCDHajHl2EQHNrS0reKz/6j7kl4p9T6gk78cCQi5KEst CgNlGbjKr2WmTQJvcUwAYNxN/LatMneshoQ6h7XPYur31KUET/sJ1Z1N0JFOho6p3axy dSNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=bz41Ul1hCF7wExgBnnf68LTu5yY/XJDD/h9+93rz1sg=; b=cRfsovCGDvCX2OV1JBQKOCymaXYD+2e8vHiXhgjEvN7AaxEVAMZ0RZvZ7eiHZCHNKe BFQetle1OYrnFbq4ZYNDdEdVPY1qb3qjBpRcZzYoxKO7CvVdR2VH+zEmhCGJJ/dy+FkR HAE7PhIBPiJseqzQJy8lVfNRKOlxSCfByu4A7JyVl5nL8ce1sdeP9pdAVABHGMK2ZZm8 H8v1KtE4kXUn4cCAsQtBnZSIAeRW3/utULCLc2wDsYOVh1slrOYQo31GbM7I/6nVlrzM 47y998/BVSlY+7uSyCzvD2AjL8/1lA95ne3iLHrHTGemS3J1gsmuzj1UHFGjBLDVCFE5 yFug== X-Gm-Message-State: AOUpUlEFo3VaGuENR215S/JlYBP7Wh+5XhGjmBZ0XSAGBJatB7zR8O1z UlkFeDzDjGzI4Yj7GyT3CjoTc7+6 X-Google-Smtp-Source: AA+uWPxBjKBvfGXq5HNl8vHXTAlGN7Ep67hFQCD3fhlG87GYU06WIpTvx+0vZNRPHWZq7Koa2wz2zA== X-Received: by 2002:a63:d54e:: with SMTP id v14-v6mr1487356pgi.264.1533714229239; Wed, 08 Aug 2018 00:43:49 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:45 +0530 Message-Id: <1533501842-24503-19-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 08 Aug 2018 07:43:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 08 Aug 2018 07:43:50 +0000 (UTC) for IP:'209.85.210.193' DOMAIN:'mail-pf1-f193.google.com' HELO:'mail-pf1-f193.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.210.193 mail-pf1-f193.google.com 209.85.210.193 mail-pf1-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 18/35] util: netdevip: use VIR_AUTOPTR for aggregate types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 08 Aug 2018 07:44:24 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevip.c | 125 +++++++++++++++++++--------------------------= ---- 1 file changed, 48 insertions(+), 77 deletions(-) diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index 78c6dcf..df19d16 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -168,10 +168,9 @@ virNetDevIPAddrAdd(const char *ifname, virSocketAddr *peer, unsigned int prefix) { - virSocketAddr *broadcast =3D NULL; - int ret =3D -1; - struct nl_msg *nlmsg =3D NULL; unsigned int recvbuflen; + VIR_AUTOPTR(virNlMsg) nlmsg =3D NULL; + VIR_AUTOPTR(virSocketAddr) broadcast =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; VIR_AUTOFREE(char *) ipStr =3D NULL; VIR_AUTOFREE(char *) peerStr =3D NULL; @@ -186,13 +185,13 @@ virNetDevIPAddrAdd(const char *ifname, !(peer && VIR_SOCKET_ADDR_VALID(peer))) { /* compute a broadcast address if this is IPv4 */ if (VIR_ALLOC(broadcast) < 0) - goto cleanup; + return -1; =20 if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to determine broadcast address for '%s/%d= '"), - ipStr, prefix); - goto cleanup; + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to determine broadcast address for '%= s/%d'"), + ipStr, prefix); + return -1; } bcastStr =3D virSocketAddrFormat(broadcast); } @@ -206,11 +205,11 @@ virNetDevIPAddrAdd(const char *ifname, if (!(nlmsg =3D virNetDevCreateNetlinkAddressMessage(RTM_NEWADDR, ifna= me, addr, prefix, broadcast, peer))) - goto cleanup; + return -1; =20 if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) - goto cleanup; + return -1; =20 =20 if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) { @@ -220,14 +219,10 @@ virNetDevIPAddrAdd(const char *ifname, peerStr ? " peer " : "", peerStr ? peerStr : "", bcastStr ? " bcast " : "", bcastStr ? bcastStr : "", ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - nlmsg_free(nlmsg); - VIR_FREE(broadcast); - return ret; + return 0; } =20 =20 @@ -246,30 +241,26 @@ virNetDevIPAddrDel(const char *ifname, virSocketAddr *addr, unsigned int prefix) { - int ret =3D -1; - struct nl_msg *nlmsg =3D NULL; unsigned int recvbuflen; + VIR_AUTOPTR(virNlMsg) nlmsg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!(nlmsg =3D virNetDevCreateNetlinkAddressMessage(RTM_DELADDR, ifna= me, addr, prefix, NULL, NULL))) - goto cleanup; + return -1; =20 if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) - goto cleanup; + return -1; =20 if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) { virReportError(VIR_ERR_SYSTEM_ERROR, _("Error removing IP address from %s"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - nlmsg_free(nlmsg); - return ret; + return 0; } =20 =20 @@ -292,8 +283,6 @@ virNetDevIPRouteAdd(const char *ifname, virSocketAddrPtr gateway, unsigned int metric) { - int ret =3D -1; - struct nl_msg *nlmsg =3D NULL; struct nlmsghdr *resp =3D NULL; unsigned int recvbuflen; unsigned int ifindex; @@ -304,6 +293,7 @@ virNetDevIPRouteAdd(const char *ifname, int errCode; virSocketAddr defaultAddr; virSocketAddrPtr actualAddr; + VIR_AUTOPTR(virNlMsg) nlmsg =3D NULL; VIR_AUTOFREE(char *) toStr =3D NULL; VIR_AUTOFREE(char *) viaStr =3D NULL; =20 @@ -315,10 +305,10 @@ virNetDevIPRouteAdd(const char *ifname, int family =3D VIR_SOCKET_ADDR_FAMILY(gateway); if (family =3D=3D AF_INET) { if (virSocketAddrParseIPv4(&defaultAddr, VIR_SOCKET_ADDR_IPV4_= ALL) < 0) - goto cleanup; + return -1; } else { if (virSocketAddrParseIPv6(&defaultAddr, VIR_SOCKET_ADDR_IPV6_= ALL) < 0) - goto cleanup; + return -1; } =20 actualAddr =3D &defaultAddr; @@ -330,17 +320,17 @@ virNetDevIPRouteAdd(const char *ifname, =20 if (virNetDevGetIPAddressBinary(actualAddr, &addrData, &addrDataLen) <= 0 || virNetDevGetIPAddressBinary(gateway, &gatewayData, &addrDataLen) <= 0) - goto cleanup; + return -1; =20 /* Get the interface index */ if ((ifindex =3D if_nametoindex(ifname)) =3D=3D 0) - goto cleanup; + return -1; =20 if (!(nlmsg =3D nlmsg_alloc_simple(RTM_NEWROUTE, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL))) { virReportOOMError(); - goto cleanup; + return -1; } =20 memset(&rtmsg, 0, sizeof(rtmsg)); @@ -369,22 +359,19 @@ virNetDevIPRouteAdd(const char *ifname, =20 if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) - goto cleanup; + return -1; =20 if ((errCode =3D virNetlinkGetErrorCode(resp, recvbuflen)) < 0) { virReportSystemError(errCode, _("Error adding route to %s"), ifnam= e); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - nlmsg_free(nlmsg); - return ret; + return 0; =20 buffer_too_small: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 =20 @@ -443,12 +430,11 @@ virNetDevIPParseDadStatus(struct nlmsghdr *nlh, int l= en, int virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_t count) { - struct nl_msg *nlmsg =3D NULL; struct ifaddrmsg ifa; unsigned int recvbuflen; - int ret =3D -1; bool dad =3D true; time_t max_time =3D time(NULL) + VIR_DAD_WAIT_TIMEOUT; + VIR_AUTOPTR(virNlMsg) nlmsg =3D NULL; =20 if (!(nlmsg =3D nlmsg_alloc_simple(RTM_GETADDR, NLM_F_REQUEST | NLM_F_DUMP))) { @@ -462,7 +448,7 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_= t count) if (nlmsg_append(nlmsg, &ifa, sizeof(ifa), NLMSG_ALIGNTO) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 /* Periodically query netlink until DAD finishes on all known addresse= s. */ @@ -471,12 +457,12 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, siz= e_t count) =20 if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) - goto cleanup; + return -1; =20 if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) { virReportError(VIR_ERR_SYSTEM_ERROR, "%s", _("error reading DAD state information")); - goto cleanup; + return -1; } =20 /* Parse response. */ @@ -490,12 +476,10 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, siz= e_t count) _("Duplicate Address Detection " "not finished in %d seconds"), VIR_DAD_WAIT_TIMEO= UT); } else { - ret =3D 0; + return 0; } =20 - cleanup: - nlmsg_free(nlmsg); - return ret; + return -1; } =20 static int @@ -588,7 +572,6 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nlm= sghdr *resp, bool virNetDevIPCheckIPv6Forwarding(void) { - struct nl_msg *nlmsg =3D NULL; bool valid =3D false; struct rtgenmsg genmsg; size_t i; @@ -597,6 +580,7 @@ virNetDevIPCheckIPv6Forwarding(void) .devices =3D NULL, .ndevices =3D 0 }; + VIR_AUTOPTR(virNlMsg) nlmsg =3D NULL; =20 =20 /* Prepare the request message */ @@ -650,7 +634,6 @@ virNetDevIPCheckIPv6Forwarding(void) } =20 cleanup: - nlmsg_free(nlmsg); for (i =3D 0; i < data.ndevices; i++) VIR_FREE(data.devices[i]); return valid; @@ -665,24 +648,23 @@ virNetDevIPAddrAdd(const char *ifname, virSocketAddr *peer, unsigned int prefix) { - virCommandPtr cmd =3D NULL; virSocketAddr broadcast; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) addrstr =3D NULL; VIR_AUTOFREE(char *) bcaststr =3D NULL; VIR_AUTOFREE(char *) peerstr =3D NULL; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) - goto cleanup; + return -1; =20 if (peer && VIR_SOCKET_ADDR_VALID(peer) && !(peerstr =3D virSocketAddr= Format(peer))) - goto cleanup; + return -1; =20 /* format up a broadcast address if this is IPv4 */ if (!peerstr && ((VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET)) && ((virSocketAddrBroadcastByPrefix(addr, prefix, &broadcast) < 0) || !(bcaststr =3D virSocketAddrFormat(&broadcast))))) { - goto cleanup; + return -1; } =20 # ifdef IFCONFIG_PATH @@ -710,12 +692,9 @@ virNetDevIPAddrAdd(const char *ifname, # endif =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -724,12 +703,11 @@ virNetDevIPAddrDel(const char *ifname, virSocketAddr *addr, unsigned int prefix) { - virCommandPtr cmd =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) addrstr =3D NULL; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) - goto cleanup; + return -1; # ifdef IFCONFIG_PATH cmd =3D virCommandNew(IFCONFIG_PATH); virCommandAddArg(cmd, ifname); @@ -747,12 +725,9 @@ virNetDevIPAddrDel(const char *ifname, # endif =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -763,15 +738,14 @@ virNetDevIPRouteAdd(const char *ifname, virSocketAddrPtr gateway, unsigned int metric) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) addrstr =3D NULL; VIR_AUTOFREE(char *) gatewaystr =3D NULL; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) - goto cleanup; + return -1; if (!(gatewaystr =3D virSocketAddrFormat(gateway))) - goto cleanup; + return -1; cmd =3D virCommandNew(IP_PATH); virCommandAddArgList(cmd, "route", "add", NULL); virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix); @@ -780,12 +754,9 @@ virNetDevIPRouteAdd(const char *ifname, virCommandAddArgFormat(cmd, "%u", metric); =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714244103432.8822326317645; Wed, 8 Aug 2018 00:44:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C91DA3082144; Wed, 8 Aug 2018 07:44:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 901DE277D2; Wed, 8 Aug 2018 07:44:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 10AC124F62; Wed, 8 Aug 2018 07:44:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787htx7005739 for ; Wed, 8 Aug 2018 03:43:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8BAE810694EC; Wed, 8 Aug 2018 07:43:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7E4D81001F49 for ; Wed, 8 Aug 2018 07:43:53 +0000 (UTC) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.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 15EAC30832F5 for ; Wed, 8 Aug 2018 07:43:52 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id l9-v6so711094pff.9 for ; Wed, 08 Aug 2018 00:43:52 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=0yjDPX/1LjXTUbVaCDH2E8QU/WW55zgVnVxhxVAlGJA=; b=Yx23Kmf+E/8eZ8diPfIBSRQNF636ubLkq8iOG71Hcms7k0tA5dn5S64xvhhKBl6l+v Rph/Xm8twkGJbbylxr6tTO39wOjnZx2Z7Q0T56/tt7n1Nwo0PJXDTqZ6BxgypbqN6/+2 PubxlN/AAZXn3sWfpn+pRDO99w0brAcdcjgWhwjx4B5KCVMgJKIZF61GO4k/WV1X30km 37n0ECtVqWjD5elAMgFTx335Td2ToZKdTPbAqvtDeW6K/2Bi02/oPK76nhOX8Uz4FdWd hDnv69GzOFdz6gHernIv38VIwayH40vVeXs3C2pU7egudenzCUwPsayZx/BFNX8dnGWw jkRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=0yjDPX/1LjXTUbVaCDH2E8QU/WW55zgVnVxhxVAlGJA=; b=mq96h6SLQHC60P3CU8enYojybtlbyciTqjXILqAWSFPh+OB6yOed+9NnxYgYOw35Ok zHWNbVhTODEidid39Is4+6V0hax8xnHtECPVfgNKd/EWjBgYlVK2xRWQsGAMFRPl4txQ kTWzOHsh3nWdH/EW/eS0AIFJWv5eaUiPBH/tE2tpaF8iPzuYAKLxcuS/W7Js78FBFhzQ GJcW4orquduJNx/ZbSp9Tbk+uGWUZ2B9yK+B5Iu3/V2XadEk9++XzGB3uiBgMy7yOdmv zKRlYONT4xZDlSCODOCDeb1y8FoRAUV2DibtIfuu9sz8ncUWKK0+SHlB5HLdTQeXOX8V RrmQ== X-Gm-Message-State: AOUpUlEsn3ZbDSygOGBG/FClxFOmoLxZPh4U8v2v2p2yo9ctDQ2hmU8D efoJN8DaAgGnVdERkd7QBi6CE32V X-Google-Smtp-Source: AA+uWPyOJpc41DLjk1sSHSTdHpchQ6xVBi6gIiB34GszL16zL0pADO17WBa3bQ/B9lLwac7jxYS/8Q== X-Received: by 2002:a63:8548:: with SMTP id u69-v6mr1464872pgd.346.1533714231285; Wed, 08 Aug 2018 00:43:51 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:46 +0530 Message-Id: <1533501842-24503-20-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:43:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:43:52 +0000 (UTC) for IP:'209.85.210.194' DOMAIN:'mail-pf1-f194.google.com' HELO:'mail-pf1-f194.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.210.194 mail-pf1-f194.google.com 209.85.210.194 mail-pf1-f194.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 19/35] util: netdevmacvlan: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 08 Aug 2018 07:44:02 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virNetlinkCallbackDataPtr is declared using VIR_AUTOPTR, the function virNetlinkCallbackDataFree will be run automatically on it when it goes out of scope. This commit also adds an intermediate typedef for virNetlinkCallbackData type for use with the cleanup macros. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevmacvlan.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index fb41bf9..91c6244 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -576,7 +576,7 @@ static const uint32_t modeMap[VIR_NETDEV_MACVLAN_MODE_L= AST] =3D { }; =20 /* Struct to hold the state and configuration of a 802.1qbg port */ -struct virNetlinkCallbackData { +struct _virNetlinkCallbackData { char *cr_ifname; virNetDevVPortProfilePtr virtPortProfile; virMacAddr macaddress; @@ -587,7 +587,8 @@ struct virNetlinkCallbackData { unsigned int linkState; }; =20 -typedef struct virNetlinkCallbackData *virNetlinkCallbackDataPtr; +typedef struct _virNetlinkCallbackData virNetlinkCallbackData; +typedef virNetlinkCallbackData *virNetlinkCallbackDataPtr; =20 # define INSTANCE_STRLEN 36 =20 @@ -870,6 +871,8 @@ virNetlinkCallbackDataFree(virNetlinkCallbackDataPtr ca= lld) VIR_FREE(calld); } =20 +VIR_DEFINE_AUTOPTR_FUNC(virNetlinkCallbackData, virNetlinkCallbackDataFree) + /** * virNetDevMacVLanVPortProfileDestroyCallback: * --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714250584755.5138059443603; Wed, 8 Aug 2018 00:44:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 805C48F242; Wed, 8 Aug 2018 07:44:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C001608EE; Wed, 8 Aug 2018 07:44:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8475124F56; Wed, 8 Aug 2018 07:44:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787i4fd005825 for ; Wed, 8 Aug 2018 03:44:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id B0D7317D2F; Wed, 8 Aug 2018 07:44:04 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A52F062929 for ; Wed, 8 Aug 2018 07:43:54 +0000 (UTC) Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 DD73A30832F3 for ; Wed, 8 Aug 2018 07:43:53 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id u24-v6so700937pfn.13 for ; Wed, 08 Aug 2018 00:43:53 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=UwN+DR+B+ttsQZjpRoVS5YvanlWgAOgJBbeG2Z1vJNQ=; b=KlV7YQOWUZOf7fhunAWg5jC1Clv6XTe48Xl/0K+RLqWfnc2OH+LcLu9kdykJGXdhuS GH8UQ/z+MFWgWPmz/GbXz4jeg+WLv7IiLt5GqRTPj49fcKIdDS6y7r4n0Ri8Ix6iZ28I bzerjrmDbaiIYGCdx7yFXuysLG0dqawQA/zvlSPbu1HQH6EnW+Ve6W6kBzjy25dEFa6w 25XvpjMMjNQXK6/A+aURGgdEy5mMqkafmS84j0E+OxG8bwY69upTHrKN57kqn/pIZ4ZW kM0Vz0Yn81q8tNw1I+2B5sVOau+gsgJLRXHOOFsxOoZJ/wnOTuFHxbGqlF1pZnI+ZVVb lYfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=UwN+DR+B+ttsQZjpRoVS5YvanlWgAOgJBbeG2Z1vJNQ=; b=MpceGkJKwThvtlpk5IV/HwydziBnjHqtVgydya5w3GALgt+FRywSivyHaKe4nPyWnb RX4J2UYzZ59AshDbuCJ1weJ8V75bthaITVMFH0YrCgZJBv9b5fJHNK+PCD9Xa1e3E09c dfmHk9LK4BzZXgmNVcuk1DB6+3Z+GGM4dBYcMmJ/qf2mkEWEayEsGcjCLAObzvRrXSBi sVL3TMFtXfFQHxs5HkywjtV9/F9/nU+RFg0HlwoQhEkjCdHIz3n65IPFRoqcbVhdsFiw VZm9V0kFrcaMdzLJ50XrXfnmfLOjYUZn8O2pZgN82vlS+eoDJQiEgbw2nR/OgFgpx34Y lEbw== X-Gm-Message-State: AOUpUlEL+VrPUQ8CctaUFek4iD3PokSb48YGgNBpcimTFo1KDchqIk3Q NG/IZ3yTr175yAAdsGgqIKwe2NWl X-Google-Smtp-Source: AA+uWPz0UBJpJZ2B2KfOdFQ+FzRAJ7I6SgEi6wtblw+GwwEW36G8SQ8F5E7BraP0+yF31x8hMAa3Lw== X-Received: by 2002:a63:4703:: with SMTP id u3-v6mr1402045pga.405.1533714233174; Wed, 08 Aug 2018 00:43:53 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:47 +0530 Message-Id: <1533501842-24503-21-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:43:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:43:53 +0000 (UTC) for IP:'209.85.210.175' DOMAIN:'mail-pf1-f175.google.com' HELO:'mail-pf1-f175.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.111 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.210.175 mail-pf1-f175.google.com 209.85.210.175 mail-pf1-f175.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 20/35] util: netdevmacvlan: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:44:09 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virnetdevmacvlan.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index 91c6244..a2ed65c 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -308,7 +308,7 @@ virNetDevMacVLanCreate(const char *ifname, int *retry) { int rc =3D -1; - struct nlmsghdr *resp =3D NULL; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC }; int ifindex; @@ -403,7 +403,6 @@ virNetDevMacVLanCreate(const char *ifname, rc =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -452,7 +451,7 @@ virNetDevMacVLanTapOpen(const char *ifname, { int ret =3D -1; int ifindex; - char *tapname =3D NULL; + VIR_AUTOFREE(char *) tapname =3D NULL; size_t i =3D 0; =20 if (virNetDevGetIndex(ifname, &ifindex) < 0) @@ -487,7 +486,6 @@ virNetDevMacVLanTapOpen(const char *ifname, while (i--) VIR_FORCE_CLOSE(tapfd[i]); } - VIR_FREE(tapname); return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714246538455.4072779923366; Wed, 8 Aug 2018 00:44:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 91FC381DE5; Wed, 8 Aug 2018 07:44:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5D3093001A49; Wed, 8 Aug 2018 07:44:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0D2CE24F65; Wed, 8 Aug 2018 07:44:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787i1TH005802 for ; Wed, 8 Aug 2018 03:44:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id EE213308BDBA; Wed, 8 Aug 2018 07:44:01 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E1242308BDB7 for ; Wed, 8 Aug 2018 07:43:57 +0000 (UTC) Received: from mail-pl0-f46.google.com (mail-pl0-f46.google.com [209.85.160.46]) (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 83FDE308A95E for ; Wed, 8 Aug 2018 07:43:56 +0000 (UTC) Received: by mail-pl0-f46.google.com with SMTP id f6-v6so669525plo.1 for ; Wed, 08 Aug 2018 00:43:56 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=y+Ew1V1xx5r+Dbk0kHsZmTUCh58kYMwyPpVE/Y1edJU=; b=rnrvbxvZMo5mEUxPs/Wx7vI9+6gsfoUH0DZY7o+luKwLdMLjs/u16M4LGV51nRJ2+w gez2NfZREKm78feG8WVSIabY4FDW299Y3GKpEUA1QiJOiWVCx3ZYE/BWoGJRYQG4pSLv XV5Mw4cBy+XGgeSHz7rGpOxkI4vPLh+3bRI/UTxKjSvOsrXd42PEr1bxQnF1HmoXR8Yq puszgwOwESIFYJuM5TBMrQQe/VH/Ob4KOtOnWOPTH5wzFz5zZyXS0kxxxpBscYZptGit Swgu2C0ww5kkxESFkvfiwr+GwAbNYxiyAXB29NnvP/gwjV0MTGp6+Pun9oNoX6PhFcbH uv2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=y+Ew1V1xx5r+Dbk0kHsZmTUCh58kYMwyPpVE/Y1edJU=; b=U8OoEeJtR1djPKGIgQbibCVYmsfOV1Thqab2EpBOrSkU+Q6jmjN8xwQ7cuQB3hF0EE ddfZN0c7x/lo/pTEImAw1x+Z1finkfPW5ULWi99Ai/9phRhbV8UsHAkb7bqYh/m+sC3W 81Qwde/pZoJPteixr5CEkG39CTUsI3r0wuxXjL8h5HoK/PYRtpaSsqgIDM9kg9Y52I+N t2j265lv9Aor5pPJF5BUI4xmNSSyxFRRtUahKAfEEsaeBb86r3953IEYcP3pYaTumqTr KG1yyOXuOk6xRZUGNgRoG2zKx5aqUtLgHusI9NlxW697iKjvcfpXr/shWiiKfFued3Ee pC5w== X-Gm-Message-State: AOUpUlFYQkxtc2lazT63v7PN4IRdUgtILG2DLXxzLBElJQtneBiTZL54 Zi83vZ8QdiU4qaV1qrKygIwE9nwq X-Google-Smtp-Source: AA+uWPwWDCemckZ0FKJNuZJgmsyyFdBiukVQ6j1uQJeRIa+j+gEmwA9leqEEruKAdl7aGASNvX4rgg== X-Received: by 2002:a17:902:6b0b:: with SMTP id o11-v6mr1505005plk.214.1533714235271; Wed, 08 Aug 2018 00:43:55 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:48 +0530 Message-Id: <1533501842-24503-22-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 08 Aug 2018 07:43:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 08 Aug 2018 07:43:56 +0000 (UTC) for IP:'209.85.160.46' DOMAIN:'mail-pl0-f46.google.com' HELO:'mail-pl0-f46.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.160.46 mail-pl0-f46.google.com 209.85.160.46 mail-pl0-f46.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 21/35] util: netdevmacvlan: use VIR_AUTOPTR for aggregate types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 08 Aug 2018 07:44:05 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virnetdevmacvlan.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index a2ed65c..100507f 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -1184,9 +1184,9 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char= *ifname, } =20 if (mode =3D=3D VIR_NETDEV_MACVLAN_MODE_PASSTHRU) { - virMacAddrPtr MAC =3D NULL; - virMacAddrPtr adminMAC =3D NULL; - virNetDevVlanPtr vlan =3D NULL; + VIR_AUTOPTR(virMacAddr) MAC =3D NULL; + VIR_AUTOPTR(virMacAddr) adminMAC =3D NULL; + VIR_AUTOPTR(virNetDevVlan) vlan =3D NULL; =20 if ((virNetDevReadNetConfig(linkdev, -1, stateDir, &adminMAC, &vlan, &MAC) =3D=3D 0) && @@ -1194,9 +1194,6 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char= *ifname, =20 ignore_value(virNetDevSetNetConfig(linkdev, -1, adminMAC, vlan, MAC, !!vlan= )); - VIR_FREE(MAC); - VIR_FREE(adminMAC); - virNetDevVlanFree(vlan); } } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714258855953.5734319313406; Wed, 8 Aug 2018 00:44:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66DED3084024; Wed, 8 Aug 2018 07:44:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2369E10694F2; Wed, 8 Aug 2018 07:44:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B9F481800C9C; Wed, 8 Aug 2018 07:44:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.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 w787iDov005902 for ; Wed, 8 Aug 2018 03:44:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id D48673083332; Wed, 8 Aug 2018 07:44:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA6083083331 for ; Wed, 8 Aug 2018 07:43:58 +0000 (UTC) Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) (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 000FF30832D2 for ; Wed, 8 Aug 2018 07:43:57 +0000 (UTC) Received: by mail-pl0-f66.google.com with SMTP id d5-v6so666056pll.4 for ; Wed, 08 Aug 2018 00:43:57 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=yqh5y/xyzAhg8E54Bf49i2GyB9uCe9KG/jTqINVaPbQ=; b=OTmZmvdMdBc+fligSWiB5MTrBxejkkW5CCqrWnCFRxsYT17vuquQEP3zVElK8SkQss UwuLbB0KUpGY39OY2IwezVEuhumLLVYUWjAZEw6KQGk4fTGvycp5+jomgwIelNrrrslA pEmvwZ6WGK2ap8h805sFgD4nMleFB4i6zL8o0HOHNghPsrwURh/p5ia962bejrxtoe00 wXHTTqFALPt1x5D9gIsrK98pOZFTjl5M7xj0s/k1Qjv7HGPIiqyZX5gEBFiNTeI9sf4I Vz1+zHmkf5uD1OYZ0kZ4WudT58PII+r3VPyniyLhdT/27knTLp5CWFv8tgK09BK/UEbI vqNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=yqh5y/xyzAhg8E54Bf49i2GyB9uCe9KG/jTqINVaPbQ=; b=LZIPKB5r5dzHQAfrNHst3U0SVrl2BN7CG58uaIs5hsYzDL/xNXYdewqQFWgiG13/lM erze2icrhiXnUtqqqlAr+O0krigqmvaaYu5ka2o28PJMXqPcTTYObxsn7svegYPKc9Jg CnB9YKhmhklrqsG35ecV+Xf7AnS7SNxqRsDM+sJsiatmGRWF+N4EvceiOS4k5u00i3nj FNIuAUybWlml0Y3nZs0EmPePWoEIEWO3V8VObW4XELy5UuGLY7GhKHwGbP8CMKug6NVQ 0bQKsruMB6qwhSHv29RY1kISffrhhVb8ohiaHVb4g4PfWw8HoP98/TBWP6EjaPAfEENR 4hHQ== X-Gm-Message-State: AOUpUlFmoAYx0mLM+DhTMe+GZCHJm9qO2mxhkJ/qF3tux1nfEc//2Pma T3a1/rN/aPgiBQaogktXDLtnuGZz X-Google-Smtp-Source: AA+uWPwUnoXefTLmuUpTen2HkuYGquAuB3KoJFL7Og1y1ZhpdxinD/mr1s0b6PpLr7MFQOlU0NjTjg== X-Received: by 2002:a17:902:d906:: with SMTP id c6-v6mr1497366plz.65.1533714237243; Wed, 08 Aug 2018 00:43:57 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:49 +0530 Message-Id: <1533501842-24503-23-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:43:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:43:58 +0000 (UTC) for IP:'209.85.160.66' DOMAIN:'mail-pl0-f66.google.com' HELO:'mail-pl0-f66.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.160.66 mail-pl0-f66.google.com 209.85.160.66 mail-pl0-f66.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 22/35] util: netdevopenvswitch: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 08 Aug 2018 07:44:17 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevopenvswitch.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitc= h.c index d1c5cf4..eff6b0f 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -149,10 +149,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, char macaddrstr[VIR_MAC_STRING_BUFLEN]; char ifuuidstr[VIR_UUID_STRING_BUFLEN]; char vmuuidstr[VIR_UUID_STRING_BUFLEN]; - char *attachedmac_ex_id =3D NULL; - char *ifaceid_ex_id =3D NULL; - char *profile_ex_id =3D NULL; - char *vmid_ex_id =3D NULL; + VIR_AUTOFREE(char *) attachedmac_ex_id =3D NULL; + VIR_AUTOFREE(char *) ifaceid_ex_id =3D NULL; + VIR_AUTOFREE(char *) profile_ex_id =3D NULL; + VIR_AUTOFREE(char *) vmid_ex_id =3D NULL; =20 virMacAddrFormat(macaddr, macaddrstr); virUUIDFormat(ovsport->interfaceID, ifuuidstr); @@ -209,10 +209,6 @@ int virNetDevOpenvswitchAddPort(const char *brname, co= nst char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(attachedmac_ex_id); - VIR_FREE(ifaceid_ex_id); - VIR_FREE(vmid_ex_id); - VIR_FREE(profile_ex_id); virCommandFree(cmd); return ret; } @@ -339,10 +335,10 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, virDomainInterfaceStatsPtr stats) { virCommandPtr cmd =3D NULL; - char *output; char *tmp; bool gotStats =3D false; int ret =3D -1; + VIR_AUTOFREE(char *) output =3D NULL; =20 /* Just ensure the interface exists in ovs */ cmd =3D virCommandNew(OVSVSCTL); @@ -399,7 +395,6 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, ret =3D 0; =20 cleanup: - VIR_FREE(output); virCommandFree(cmd); return ret; } @@ -481,7 +476,7 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, size_t ntokens =3D 0; int status; int ret =3D -1; - char *ovs_timeout =3D NULL; + VIR_AUTOFREE(char *) ovs_timeout =3D NULL; =20 /* Openvswitch vhostuser path are hardcoded to * //openvswitch/ @@ -513,7 +508,6 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, cleanup: virStringListFreeCount(tokens, ntokens); virCommandFree(cmd); - VIR_FREE(ovs_timeout); return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153371425306014.83791557894483; Wed, 8 Aug 2018 00:44:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D120146291; Wed, 8 Aug 2018 07:44:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 20F7C308BDB7; Wed, 8 Aug 2018 07:44:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8132F24F5B; Wed, 8 Aug 2018 07:44:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787i5lC005845 for ; Wed, 8 Aug 2018 03:44:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id D519B608F3; Wed, 8 Aug 2018 07:44:05 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C64F66090A for ; Wed, 8 Aug 2018 07:44:01 +0000 (UTC) Received: from mail-pl0-f53.google.com (mail-pl0-f53.google.com [209.85.160.53]) (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 C39D7C04AC5A for ; Wed, 8 Aug 2018 07:43:59 +0000 (UTC) Received: by mail-pl0-f53.google.com with SMTP id w19-v6so655949ply.8 for ; Wed, 08 Aug 2018 00:43:59 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=Dy5sFYUDmQ+QcvyXXoJwx6PBURrz/K/WUV5M7FgTzVQ=; b=mbuypsDGTEYGVNkoWKQ0ajhh/eJyR9nY2NnW5EJ/+9bgkJUa0OLUvYoeawU6KNJpI/ SmQ4ph/vYKoLy0NKN9gMHC0rJtNWDF3y+ojr2zCGMLSY7Xu4vjhUiPxKKUKtcwAZE2J7 L5sWKHFUgJkAAcfnOazzXEGm68dYpTKlKS3SwtYH3bldLmDHlJSmdQUAYll3rZ2q8lTm rZU3cHkMYNE3QVa9U04o7QbWIzh2pyZiE9c7DIa50vBoDB99GBR9YqxsgSt9mXh/V0RL ZHpeYyK7w7cCjonAWIivATWywJZB7a7yit87qIvqoR0F+gIkFymvZH3VfvgD6chyxCMY IXDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Dy5sFYUDmQ+QcvyXXoJwx6PBURrz/K/WUV5M7FgTzVQ=; b=sUMbrygqQ9n+12asYzskGv44z2jXSPF2XbnFdEbzLgHQpyLfNYXDgJsmvuo3ByaHtj VC05D6196rn7BkgehgbKHe8NO2q6QmUsHj88tETLNR0R1HwIxGqZoiHpWKIuua0FGol9 CZrLQeEIrHFWkpeVeNRpJjmD5VMXyJ1NLfRmCXd6LJZINqK359qRgtuwJrTsHdOJnMdx bCqri4uDz+/NYKmc7jGW74hfqbHh8QSmJUiIaW9d4CmCwndsdLJwtnUBYZOX7BFtqinW W5eO1oDTu3jeqDccFMo8k64oyyClvVA+QLUh5RMtcvnZrxaEh8fE512Gg8jlYmBl/J3P XhLg== X-Gm-Message-State: AOUpUlHsnApuIbzxwykYo4xBUmEhL6o9GNEH/fVgVAYX1BaIT13Bivqk e+u974Rs5olQY43I9Pvt+esSUMKc X-Google-Smtp-Source: AA+uWPyVgIH9ARCNpODalfpvtVKwaIznfP6vWKGXWrxPdvXTPGzLPd+gDJueosVNvptzpA4uHrBt2Q== X-Received: by 2002:a17:902:403:: with SMTP id 3-v6mr1541860ple.39.1533714239019; Wed, 08 Aug 2018 00:43:59 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:50 +0530 Message-Id: <1533501842-24503-24-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 08 Aug 2018 07:43:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 08 Aug 2018 07:43:59 +0000 (UTC) for IP:'209.85.160.53' DOMAIN:'mail-pl0-f53.google.com' HELO:'mail-pl0-f53.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.160.53 mail-pl0-f53.google.com 209.85.160.53 mail-pl0-f53.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 23/35] util: netdevopenvswitch: use VIR_AUTOPTR for aggregate types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 08 Aug 2018 07:44:11 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevopenvswitch.c | 80 ++++++++++++++-----------------------= ---- 1 file changed, 27 insertions(+), 53 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitc= h.c index eff6b0f..d34fb6f 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -144,11 +144,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, virNetDevVPortProfilePtr ovsport, virNetDevVlanPtr virtVlan) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; char macaddrstr[VIR_MAC_STRING_BUFLEN]; char ifuuidstr[VIR_UUID_STRING_BUFLEN]; char vmuuidstr[VIR_UUID_STRING_BUFLEN]; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) attachedmac_ex_id =3D NULL; VIR_AUTOFREE(char *) ifaceid_ex_id =3D NULL; VIR_AUTOFREE(char *) profile_ex_id =3D NULL; @@ -160,17 +159,17 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, =20 if (virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=3D\"%s\= "", macaddrstr) < 0) - goto cleanup; + return -1; if (virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=3D\"%s\"", ifuuidstr) < 0) - goto cleanup; + return -1; if (virAsprintf(&vmid_ex_id, "external-ids:vm-id=3D\"%s\"", vmuuidstr) < 0) - goto cleanup; + return -1; if (ovsport->profileID[0] !=3D '\0') { if (virAsprintf(&profile_ex_id, "external-ids:port-profile=3D\"%s\= "", ovsport->profileID) < 0) - goto cleanup; + return -1; } =20 cmd =3D virCommandNew(OVSVSCTL); @@ -179,7 +178,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, con= st char *ifname, ifname, "--", "add-port", brname, ifname, NULL); =20 if (virNetDevOpenvswitchConstructVlans(cmd, virtVlan) < 0) - goto cleanup; + return -1; =20 if (ovsport->profileID[0] =3D=3D '\0') { virCommandAddArgList(cmd, @@ -204,13 +203,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to add port %s to OVS bridge %s"), ifname, brname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -223,8 +219,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, con= st char *ifname, */ int virNetDevOpenvswitchRemovePort(const char *brname ATTRIBUTE_UNUSED, co= nst char *ifname) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNew(OVSVSCTL); virNetDevOpenvswitchAddTimeout(cmd); @@ -233,13 +228,10 @@ int virNetDevOpenvswitchRemovePort(const char *brname= ATTRIBUTE_UNUSED, const ch if (virCommandRun(cmd, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to delete port %s from OVS"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -253,9 +245,8 @@ int virNetDevOpenvswitchRemovePort(const char *brname A= TTRIBUTE_UNUSED, const ch */ int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname) { - virCommandPtr cmd =3D NULL; size_t len; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNew(OVSVSCTL); virNetDevOpenvswitchAddTimeout(cmd); @@ -269,7 +260,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, = const char *ifname) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to run command to get OVS port data for " "interface %s"), ifname); - goto cleanup; + return -1; } =20 /* Wipeout the newline, if it exists */ @@ -277,10 +268,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate,= const char *ifname) if (len > 0) (*migrate)[len - 1] =3D '\0'; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -294,8 +282,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, = const char *ifname) */ int virNetDevOpenvswitchSetMigrateData(char *migrate, const char *ifname) { - virCommandPtr cmd =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!migrate) { VIR_DEBUG("No OVS port data for interface %s", ifname); @@ -312,13 +299,10 @@ int virNetDevOpenvswitchSetMigrateData(char *migrate,= const char *ifname) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to run command to set OVS port data for " "interface %s"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -334,10 +318,9 @@ int virNetDevOpenvswitchInterfaceStats(const char *ifname, virDomainInterfaceStatsPtr stats) { - virCommandPtr cmd =3D NULL; char *tmp; bool gotStats =3D false; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) output =3D NULL; =20 /* Just ensure the interface exists in ovs */ @@ -350,7 +333,7 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, /* no ovs-vsctl or interface 'ifname' doesn't exists in ovs */ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Interface not found")); - goto cleanup; + return -1; } =20 #define GET_STAT(name, member) \ @@ -369,7 +352,7 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, *tmp !=3D '\n') { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ _("Fail to parse ovs-vsctl output")); \ - goto cleanup; \ + return -1; \ } \ gotStats =3D true; \ } \ @@ -389,14 +372,10 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, if (!gotStats) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Interface doesn't have any statistics")); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -470,12 +449,12 @@ int virNetDevOpenvswitchGetVhostuserIfname(const char *path, char **ifname) { - virCommandPtr cmd =3D NULL; char *tmpIfname =3D NULL; char **tokens =3D NULL; size_t ntokens =3D 0; int status; int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) ovs_timeout =3D NULL; =20 /* Openvswitch vhostuser path are hardcoded to @@ -507,7 +486,6 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, =20 cleanup: virStringListFreeCount(tokens, ntokens); - virCommandFree(cmd); return ret; } =20 @@ -523,8 +501,7 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, int virNetDevOpenvswitchUpdateVlan(const char *ifname, virNetDevVlanPtr virtVlan) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNew(OVSVSCTL); virNetDevOpenvswitchAddTimeout(cmd); @@ -535,16 +512,13 @@ int virNetDevOpenvswitchUpdateVlan(const char *ifname, "--", "--if-exists", "set", "Port", ifname, NULL); =20 if (virNetDevOpenvswitchConstructVlans(cmd, virtVlan) < 0) - goto cleanup; + return -1; =20 if (virCommandRun(cmd, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to set vlan configuration on port %s"), i= fname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714287020398.676968365221; Wed, 8 Aug 2018 00:44:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A4E2A81E04; Wed, 8 Aug 2018 07:44:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6D37D2C32A; Wed, 8 Aug 2018 07:44:44 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 236541800B80; Wed, 8 Aug 2018 07:44:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787iYw0006124 for ; Wed, 8 Aug 2018 03:44:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id B06786C513; Wed, 8 Aug 2018 07:44:34 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9DDA218EFA for ; Wed, 8 Aug 2018 07:44:02 +0000 (UTC) Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 B43505F733 for ; Wed, 8 Aug 2018 07:44:01 +0000 (UTC) Received: by mail-pg1-f178.google.com with SMTP id x5-v6so686413pgp.7 for ; Wed, 08 Aug 2018 00:44:01 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=WEDowZtGFO2Ukdj8jeOh44aqkDDb4DoWN7+mC+71JL0=; b=f0Bumapk31lYQPyM5vHDSSE7kET/BA/8pgru6nJhqqBC054sBV9MgtowO0+w8WIkIQ sA30UT11aT5age+BU8G020B24S5Wp5KS4FC3x+4iQDag4BTUGV0QxZRvgeJrr26EJfB7 4DEg2bhcxEAv38IQlzsGBn+UdMUbvxUTTiEPgNBSsCs0fZZ1x6ygatbB1BvcNE+UcNd6 H2s8HdXdJ43N7jhH05CHvhlpE2ywmrETj9ur9WFwoctEQ5Jq75bs1zM3YpmJZmlH7Dfs y8NIHiZyTSA2iTjRaZCqwcXAa4UQTNjPOaJi0nRWF8z9RSnTsIBuVRIrWW/HL56HpaoN Mo9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=WEDowZtGFO2Ukdj8jeOh44aqkDDb4DoWN7+mC+71JL0=; b=ets3dO4YxBttInc1B/pssKY6LgupvHMdzyyVPYgj6OqjQ20kvhnCDIwzk1Emht0coF OHp4j2oATljRBpro+PDLhSPqlAIaW0CWA05zvPfLKA7T9W3/wYQCsk0JpikOXm/mpqxC Zgv+EHLLs81rWiii8eyEgsbbkTkk12D19URM0lJ5ruzUY6mK8UZ0XVkFW1TQZPHEynKe uNztJqFnp01EKw3YT1TjGvZX6q20PVOQe3y5tIbMUJ0yGoTEUnR4J/grFcZZfCxU7Mck gsJl/98unqns151z4/6b7VlRt2q39qSDPrMOLZwbUrOXtI4f6Qc8k7uugJXkQ3IJE7ws UIZA== X-Gm-Message-State: AOUpUlHkxXC1yW2WJiSMFpzncUkeVAIKmQGBR30+4tsf4oyAZnSxaBQd /oZXYI/kkwxEahuUf9OziS1PZPJt X-Google-Smtp-Source: AA+uWPz24sbQzB84ItI/Ql+f8GWUgAvJVdFg4bvSEJAfPxf3/XY2ozC0pNTJL/ZN3PAXVg3rR/wFGw== X-Received: by 2002:a63:9d47:: with SMTP id i68-v6mr1463264pgd.172.1533714240974; Wed, 08 Aug 2018 00:44:00 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:51 +0530 Message-Id: <1533501842-24503-25-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 08 Aug 2018 07:44:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 08 Aug 2018 07:44:01 +0000 (UTC) for IP:'209.85.215.178' DOMAIN:'mail-pg1-f178.google.com' HELO:'mail-pg1-f178.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.215.178 mail-pg1-f178.google.com 209.85.215.178 mail-pg1-f178.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 24/35] util: netdevtap: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 08 Aug 2018 07:44:45 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virnetdevtap.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index d432577..c2c2e73 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -400,16 +400,14 @@ int virNetDevTapCreate(char **ifname, if (strstr(*ifname, "%d") !=3D NULL) { size_t i; for (i =3D 0; i <=3D IF_MAXUNIT; i++) { - char *newname; + VIR_AUTOFREE(char *) newname =3D NULL; if (virAsprintf(&newname, *ifname, i) < 0) goto cleanup; =20 if (virNetDevExists(newname) =3D=3D 0) { - newifname =3D newname; + VIR_STEAL_PTR(newifname, newname); break; } - - VIR_FREE(newname); } if (newifname) { VIR_FREE(*ifname); @@ -423,7 +421,7 @@ int virNetDevTapCreate(char **ifname, } =20 if (tapfd) { - char *dev_path =3D NULL; + VIR_AUTOFREE(char *) dev_path =3D NULL; if (virAsprintf(&dev_path, "/dev/%s", ifr.ifr_name) < 0) goto cleanup; =20 @@ -431,11 +429,8 @@ int virNetDevTapCreate(char **ifname, virReportSystemError(errno, _("Unable to open %s"), dev_path); - VIR_FREE(dev_path); goto cleanup; } - - VIR_FREE(dev_path); } =20 if (virNetDevSetName(ifr.ifr_name, *ifname) =3D=3D -1) --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714256043558.4953481624204; Wed, 8 Aug 2018 00:44:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5AB3B356F5; Wed, 8 Aug 2018 07:44:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 271A417C52; Wed, 8 Aug 2018 07:44:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5731C1800FD9; Wed, 8 Aug 2018 07:44:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787i4ZZ005830 for ; Wed, 8 Aug 2018 03:44:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id EE5591001938; Wed, 8 Aug 2018 07:44:04 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7A8E1001F49 for ; Wed, 8 Aug 2018 07:44:04 +0000 (UTC) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 C758236A5C9 for ; Wed, 8 Aug 2018 07:44:03 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id n7-v6so694243pgq.4 for ; Wed, 08 Aug 2018 00:44:03 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=rNBuyY2u2PaDJTxgRL7eyUcZSsBOjWcYmZLm+qqjGKU=; b=QEjdoeoVIsJ1ehSTQnKlXynAG4tHcLNQnyUOsV9mNsekJADNdRSsGnB1VMVN18IVNi VEkF+DJKf1IgMC/Ptf269CpyC/vuMAM+WYizh8wt5Y3e5zhozJ5o+bwzX8/ZRPmerHeu M9YBG4ByqlsqeJ5ftUQZmu69fayy4a4XC03bSv4A+OdbvIhqpHB2SiR3PM5+I3KHinn/ 0OGshDJZTY3uGr0+9jdQQQGOsv+JkEB9rzLzSJy+5o/J36fsQNKYp3tiuRXIXTmv93M+ bwQR6WQ1r73IYfxdrrTNyDVt3OSRYpV+OOFSy1l++9fqykvDo1yqmuUAUn14Na7t9tIA viGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=rNBuyY2u2PaDJTxgRL7eyUcZSsBOjWcYmZLm+qqjGKU=; b=hlClivwDtCfcj0ZCQGOtB7TAgV60TTpxN9LtoLI/2RfVnX1UykJsyWdVSptCbF0FNH SMPIzpyQrqzoFxr+HlMUj0uvdouYzExlHTrEz+hBPyEun5aLM6MNFe8fM4pn6+FuDAbG /rcNfLEICxyllNnmmhSTAZIt+zIJCzzZJccZcySX8xSKsVEseznte+O9X9mpxnTlm1vz JpfeUTBz/30A05XGbgYa4k5L52LjzASGsyebHXzs/dsUXexPyBUJjw2WH6D3nIUTBtia 1nne2hh0NgSokOvqLJpQ+wLFriPMRTbfSmz1GR4rYoyuAT7mMYKHoOv+7g5inZDP9u5Y +21w== X-Gm-Message-State: AOUpUlG6p+VNgBS7HICzRxIlnMoYNcWQCKo6sNKPEAJ7KTE9BnS/7K7L QAPWpSKvrg0TEdk7BAlVfxCi8MWR X-Google-Smtp-Source: AA+uWPwnqJV4HJu5dyK4RyI+OiOqpp5YFiUNgkkcwmTwcwiUk8lGbFE2bru7cwyVT62W+lxnwxhHgQ== X-Received: by 2002:a62:b20c:: with SMTP id x12-v6mr1752889pfe.64.1533714242885; Wed, 08 Aug 2018 00:44:02 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:52 +0530 Message-Id: <1533501842-24503-26-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 08 Aug 2018 07:44:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 08 Aug 2018 07:44:03 +0000 (UTC) for IP:'209.85.215.171' DOMAIN:'mail-pg1-f171.google.com' HELO:'mail-pg1-f171.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.215.171 mail-pg1-f171.google.com 209.85.215.171 mail-pg1-f171.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 25/35] util: netdevveth: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 08 Aug 2018 07:44:14 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virnetdevveth.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 6905168..8c1a7f3 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -46,12 +46,11 @@ virMutex virNetDevVethCreateMutex =3D VIR_MUTEX_INITIAL= IZER; static int virNetDevVethExists(int devNum) { int ret; - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; if (virAsprintf(&path, SYSFS_NET_DIR "vnet%d/", devNum) < 0) return -1; ret =3D virFileExists(path) ? 1 : 0; VIR_DEBUG("Checked dev vnet%d usage: %d", devNum, ret); - VIR_FREE(path); return ret; } =20 @@ -111,8 +110,6 @@ static int virNetDevVethGetFreeNum(int startDev) int virNetDevVethCreate(char** veth1, char** veth2) { int ret =3D -1; - char *veth1auto =3D NULL; - char *veth2auto =3D NULL; int vethNum =3D 0; virCommandPtr cmd =3D NULL; size_t i; @@ -125,6 +122,9 @@ int virNetDevVethCreate(char** veth1, char** veth2) #define MAX_VETH_RETRIES 10 =20 for (i =3D 0; i < MAX_VETH_RETRIES; i++) { + VIR_AUTOFREE(char *) veth1auto =3D NULL; + VIR_AUTOFREE(char *) veth2auto =3D NULL; + int status; if (!*veth1) { int veth1num; @@ -173,8 +173,6 @@ int virNetDevVethCreate(char** veth1, char** veth2) *veth1 ? *veth1 : veth1auto, *veth2 ? *veth2 : veth2auto, status); - VIR_FREE(veth1auto); - VIR_FREE(veth2auto); virCommandFree(cmd); cmd =3D NULL; } @@ -186,8 +184,6 @@ int virNetDevVethCreate(char** veth1, char** veth2) cleanup: virMutexUnlock(&virNetDevVethCreateMutex); virCommandFree(cmd); - VIR_FREE(veth1auto); - VIR_FREE(veth2auto); return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714265237156.6724716457678; Wed, 8 Aug 2018 00:44:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DCDFB81E07; Wed, 8 Aug 2018 07:44:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A5F1DCBD92; Wed, 8 Aug 2018 07:44:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 54DA11800B6B; Wed, 8 Aug 2018 07:44:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787iLj7005964 for ; Wed, 8 Aug 2018 03:44:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 755463819C; Wed, 8 Aug 2018 07:44:21 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57ECB381A5 for ; Wed, 8 Aug 2018 07:44:06 +0000 (UTC) Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 7ABE530832F3 for ; Wed, 8 Aug 2018 07:44:05 +0000 (UTC) Received: by mail-pf1-f177.google.com with SMTP id j8-v6so719505pff.6 for ; Wed, 08 Aug 2018 00:44:05 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=Jcm69QRl4cp/TfEOliVF6BQckWdfLkgcgnd/GUipF3Y=; b=dzz4vmg5cJCUrWaI0OHEqKE5MqDZCsSEq6CnCwvoPG5iXb5J+RlOt+LOTOYWj6q3xC yK9BhSZHEjxPEhlWlBAQa3mwqcsJGtm91lhCw6LYDhbJgd6djSmUI1ihiqbOluYYYLtR 7CqdvTEe7D/rbcpQyA0j3SGGaHW1bLnHMuj8BbXKVKKwkSfZ49j1kAnauVp8/WN5p0ni nzfjpp5fl/sq5XTmTb37Fnjh014Gk8oPtJ6dj7qLs7cbVBQFC1aCLXaxgjp3VbauGYg2 xRP0RncuWRT7/nzlkx9RntXUi4642irnuJscglGTG1m0QbKrBGV2v90c99l/RgDr6XmM D0Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Jcm69QRl4cp/TfEOliVF6BQckWdfLkgcgnd/GUipF3Y=; b=iPn9JRq9DH4qqVminks9IoFX2BzHryrHKTVDsd41mEuK5WQukqEz1zDZslX2XHzKmK amxr4jNVmX9jR0Yf/jgNSuGl1Lilia9wE8nOecf2eIH6DnnS1ZK4yHCKOzTMCtodL+GM vFGhE6iOnd3NaFO9YEYIUrTlUpL+ADsBZSaRKTPEEwxHHRNyh8vASmGBTMC6O1pSI3EB qg+5F2x2curgM6d+i/DlEoVK/AqDYg0CYye1j4zQhu3q7wwGqUAdc/k8T8hrvUofvFsR v/3RmoeYCOpnnWZUqX5N0N50o5nqZkRmkUX9vNvUAzesnkHZf5PIavfa/rTPJgdXbatF 4NGQ== X-Gm-Message-State: AOUpUlHQA97tLSW0Ki7+1PN5Ua5jip13wicq5te7l6AllLequ4rvuXw6 KCatgQ51UbGJLT9GpHFh9p7ncEr7 X-Google-Smtp-Source: AA+uWPwdfGBURkXQZVx/d4wtMSuEgWg5LV0yIsL8l6SP7RNhBTfK/66OVsRpJ2N//H6OKXbK87hhHA== X-Received: by 2002:a63:5542:: with SMTP id f2-v6mr1490265pgm.37.1533714244779; Wed, 08 Aug 2018 00:44:04 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:53 +0530 Message-Id: <1533501842-24503-27-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:44:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:44:05 +0000 (UTC) for IP:'209.85.210.177' DOMAIN:'mail-pf1-f177.google.com' HELO:'mail-pf1-f177.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.210.177 mail-pf1-f177.google.com 209.85.210.177 mail-pf1-f177.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 26/35] util: netdevveth: use VIR_AUTOPTR for aggregate types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 08 Aug 2018 07:44:23 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virnetdevveth.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 8c1a7f3..d2232ac 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -111,7 +111,6 @@ int virNetDevVethCreate(char** veth1, char** veth2) { int ret =3D -1; int vethNum =3D 0; - virCommandPtr cmd =3D NULL; size_t i; =20 /* @@ -124,6 +123,7 @@ int virNetDevVethCreate(char** veth1, char** veth2) for (i =3D 0; i < MAX_VETH_RETRIES; i++) { VIR_AUTOFREE(char *) veth1auto =3D NULL; VIR_AUTOFREE(char *) veth2auto =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 int status; if (!*veth1) { @@ -173,8 +173,6 @@ int virNetDevVethCreate(char** veth1, char** veth2) *veth1 ? *veth1 : veth1auto, *veth2 ? *veth2 : veth2auto, status); - virCommandFree(cmd); - cmd =3D NULL; } =20 virReportError(VIR_ERR_INTERNAL_ERROR, @@ -183,7 +181,6 @@ int virNetDevVethCreate(char** veth1, char** veth2) =20 cleanup: virMutexUnlock(&virNetDevVethCreateMutex); - virCommandFree(cmd); return ret; } =20 @@ -200,26 +197,21 @@ int virNetDevVethCreate(char** veth1, char** veth2) */ int virNetDevVethDelete(const char *veth) { - virCommandPtr cmd =3D virCommandNewArgList("ip", "link", "del", veth, = NULL); int status; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList("ip", "link", "de= l", veth, NULL); =20 if (virCommandRun(cmd, &status) < 0) - goto cleanup; + return -1; =20 if (status !=3D 0) { if (!virNetDevExists(veth)) { VIR_DEBUG("Device %s already deleted (by kernel namespace clea= nup)", veth); - ret =3D 0; - goto cleanup; + return 0; } virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to delete veth device %s"), veth); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714270054694.0235655385119; Wed, 8 Aug 2018 00:44:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7EF78C015C20; Wed, 8 Aug 2018 07:44:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D751B6252D; Wed, 8 Aug 2018 07:44:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 92CF41800B6F; Wed, 8 Aug 2018 07:44:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787iFvH005921 for ; Wed, 8 Aug 2018 03:44:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 718B765963; Wed, 8 Aug 2018 07:44:15 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5C9E16595B for ; Wed, 8 Aug 2018 07:44:08 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (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 7414030B8F84 for ; Wed, 8 Aug 2018 07:44:07 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id z8-v6so685155pgu.8 for ; Wed, 08 Aug 2018 00:44:07 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=hy7DDCMXZN+ZVPkT8xAhmQtcp8HnlHc1aOlW/voRLjc=; b=TXxau36F7BUylzkR5Nw2KP+lpl1PlqofrSjvDcvIylctbp05aEAPe7yY5YassICTrG soJxQ1AxvU454tF2wgOsCkOlaRuttaWiidw9f5wxH5pSwmsVa/CgjJXql9Ceg/GgTHoK BmwGAFiWdoBpuKWFDoirKwCFNo5zee4sPuGB9Th3YE+4tH4S5wXbG3adnp8wJbX4vRYX dzGet7t6He/gCos0GvLSdwpwo89hJQjxsltVfwh35OmcIwGVAxqcLZJKqDPa36IJBIVt 6vFv1Nez22zxz+Id0nj067cdzH/VvHn6du371XJJV+Rfj5IyFHD7/EVuRmx1WgqH4mGi Odqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=hy7DDCMXZN+ZVPkT8xAhmQtcp8HnlHc1aOlW/voRLjc=; b=WK7J9J7BbWb63y5rrwHeW+VbMi7CYAUybfmTUCrpUjuZfZp8LOgZ9UwY0WdgSnXa2C 6kQkvXK27RgzQkk66d1Kloho0Q5wRA2mtBJDLdEbHfk/4sZtezX3e/3WmKZ50s+aloW7 UTIZozb/NVtS5Cd42N9sZWjOUVL9MkDo8w04Xfar/RFtjQGyNwgjFOnPUCnVLTUZBQDn /BA5eH3iT60UqYTm0urujyDgXrzSWbRZQ5FKCMtLVMpq5iJSMXZSUwLa12LjB2BEZuHc ljuK7y8HzD7bi7FGq7QML7fNrXJrDquUzYf/QdyOFmQwadI3GgS8+kKVaa0wMPT4sjOg XaKw== X-Gm-Message-State: AOUpUlEmIrGjKOA8O7ZsQa3sc//quA3+kziPXaf3SCxJrPbZPRkT/aLm kSdpUloUJPLjJVUkjtGjHHtiTWQS X-Google-Smtp-Source: AA+uWPzby5uRhn/pymJbhyjamDm4OQ4X1kDWdGMSsdrlBKYMBqLJPIpAP7SQY0PY+tpOwunkUUpscw== X-Received: by 2002:a63:f713:: with SMTP id x19-v6mr1453800pgh.233.1533714246704; Wed, 08 Aug 2018 00:44:06 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:54 +0530 Message-Id: <1533501842-24503-28-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 08 Aug 2018 07:44:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 08 Aug 2018 07:44:07 +0000 (UTC) for IP:'209.85.215.196' DOMAIN:'mail-pg1-f196.google.com' HELO:'mail-pg1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.215.196 mail-pg1-f196.google.com 209.85.215.196 mail-pg1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 27/35] util: numa: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 08 Aug 2018 07:44:28 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnuma.c | 75 +++++++++++++++++++++-----------------------------= ---- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 784db0a..6c6be1c 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -252,8 +252,8 @@ int virNumaGetNodeCPUs(int node, virBitmapPtr *cpus) { - unsigned long *mask =3D NULL; - unsigned long *allonesmask =3D NULL; + VIR_AUTOFREE(unsigned long *) mask =3D NULL; + VIR_AUTOFREE(unsigned long *) allonesmask =3D NULL; virBitmapPtr cpumap =3D NULL; int ncpus =3D 0; int max_n_cpus =3D virNumaGetMaxCPUs(); @@ -300,8 +300,6 @@ virNumaGetNodeCPUs(int node, ret =3D ncpus; =20 cleanup: - VIR_FREE(mask); - VIR_FREE(allonesmask); virBitmapFree(cpumap); =20 return ret; @@ -566,25 +564,24 @@ virNumaGetHugePageInfo(int node, unsigned long long *page_avail, unsigned long long *page_free) { - int ret =3D -1; - char *path =3D NULL; - char *buf =3D NULL; char *end; + VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (page_avail) { if (virNumaGetHugePageInfoPath(&path, node, page_size, "nr_hugepages") < 0) - goto cleanup; + return -1; =20 if (virFileReadAll(path, 1024, &buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(buf, &end, 10, page_avail) < 0 || *end !=3D '\n') { virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse: %s"), buf); - goto cleanup; + return -1; } VIR_FREE(buf); VIR_FREE(path); @@ -593,25 +590,21 @@ virNumaGetHugePageInfo(int node, if (page_free) { if (virNumaGetHugePageInfoPath(&path, node, page_size, "free_hugepages") < 0) - goto cleanup; + return -1; =20 if (virFileReadAll(path, 1024, &buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(buf, &end, 10, page_free) < 0 || *end !=3D '\n') { virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse: %s"), buf); - goto cleanup; + return -1; } } =20 - ret =3D 0; - cleanup: - VIR_FREE(buf); - VIR_FREE(path); - return ret; + return 0; } =20 /** @@ -714,13 +707,13 @@ virNumaGetPages(int node, size_t *npages) { int ret =3D -1; - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(unsigned int *) tmp_size =3D NULL; + VIR_AUTOFREE(unsigned long long *) tmp_avail =3D NULL; + VIR_AUTOFREE(unsigned long long *) tmp_free =3D NULL; DIR *dir =3D NULL; int direrr =3D 0; struct dirent *entry; - unsigned int *tmp_size =3D NULL; - unsigned long long *tmp_avail =3D NULL; - unsigned long long *tmp_free =3D NULL; unsigned int ntmp =3D 0; size_t i; bool exchange; @@ -828,11 +821,7 @@ virNumaGetPages(int node, *npages =3D ntmp; ret =3D 0; cleanup: - VIR_FREE(tmp_free); - VIR_FREE(tmp_avail); - VIR_FREE(tmp_size); VIR_DIR_CLOSE(dir); - VIR_FREE(path); return ret; } =20 @@ -843,8 +832,8 @@ virNumaSetPagePoolSize(int node, unsigned long long page_count, bool add) { - int ret =3D -1; - char *nr_path =3D NULL, *nr_buf =3D NULL; + VIR_AUTOFREE(char *) nr_path =3D NULL; + VIR_AUTOFREE(char *) nr_buf =3D NULL; char *end; unsigned long long nr_count; =20 @@ -853,37 +842,35 @@ virNumaSetPagePoolSize(int node, * differently to huge pages. */ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("system pages pool can't be modified")); - goto cleanup; + return -1; } =20 if (virNumaGetHugePageInfoPath(&nr_path, node, page_size, "nr_hugepage= s") < 0) - goto cleanup; + return -1; =20 /* Firstly check, if there's anything for us to do */ if (virFileReadAll(nr_path, 1024, &nr_buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(nr_buf, &end, 10, &nr_count) < 0 || *end !=3D '\n') { virReportError(VIR_ERR_OPERATION_FAILED, _("invalid number '%s' in '%s'"), nr_buf, nr_path); - goto cleanup; + return -1; } =20 if (add) { if (!page_count) { VIR_DEBUG("Nothing left to do: add =3D true page_count =3D 0"); - ret =3D 0; - goto cleanup; + return 0; } page_count +=3D nr_count; } else { if (nr_count =3D=3D page_count) { VIR_DEBUG("Nothing left to do: nr_count =3D page_count =3D %ll= u", page_count); - ret =3D 0; - goto cleanup; + return 0; } } =20 @@ -896,40 +883,36 @@ virNumaSetPagePoolSize(int node, */ VIR_FREE(nr_buf); if (virAsprintf(&nr_buf, "%llu", page_count) < 0) - goto cleanup; + return -1; =20 if (virFileWriteStr(nr_path, nr_buf, 0) < 0) { virReportSystemError(errno, _("Unable to write to: %s"), nr_path); - goto cleanup; + return -1; } =20 /* And now do the check. */ =20 VIR_FREE(nr_buf); if (virFileReadAll(nr_path, 1024, &nr_buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(nr_buf, &end, 10, &nr_count) < 0 || *end !=3D '\n') { virReportError(VIR_ERR_OPERATION_FAILED, _("invalid number '%s' in '%s'"), nr_buf, nr_path); - goto cleanup; + return -1; } =20 if (nr_count !=3D page_count) { virReportError(VIR_ERR_OPERATION_FAILED, _("Unable to allocate %llu pages. Allocated only %l= lu"), page_count, nr_count); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(nr_buf); - VIR_FREE(nr_path); - return ret; + return 0; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714259474506.56370216294727; Wed, 8 Aug 2018 00:44:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC3A05F737; Wed, 8 Aug 2018 07:44:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 85BD8381AA; Wed, 8 Aug 2018 07:44:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B026F24F5C; Wed, 8 Aug 2018 07:44:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787iA4h005876 for ; Wed, 8 Aug 2018 03:44:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 45BD0308BDBA; Wed, 8 Aug 2018 07:44:10 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3BEEA308BDB6 for ; Wed, 8 Aug 2018 07:44:10 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (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 4B51C307D85A for ; Wed, 8 Aug 2018 07:44:09 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id u24-v6so701257pfn.13 for ; Wed, 08 Aug 2018 00:44:09 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=PyS2hndPCwJupUgY8nfMlWEj38wGiuTXbh1XZg2iG0U=; b=JOSBH8MH10oHWfqLTOTH7Ae3LLLOKjAfo19TSFX+t/qdDnD/B/blQY6zMAQ+CyeUsF yrmcs7yzyPJ5Pyrs0OMazXhStfQjrW4g9ewB6auYOKQiowU7DXaEGVJUto64QbRV6sIP PJoQ+Boemq6rNaVWZ2g5JUjJ5MD8d0mv7HN4PgNRdEpDgu0yspMVo9IOHCn6s/X0Z+mq y+BLahyOymhNTFl1CLDA6eYk4bgQGXZg8YAM33eC2n0pkEHQ3fHF61XulXCtrA8DgeTE LbhQRvCBYnjyFWJUteaVdYUSmAmnvlCeP09/cQaPxYxyD2eNnxjZnhgH7lQtEy8kI0DV kUpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=PyS2hndPCwJupUgY8nfMlWEj38wGiuTXbh1XZg2iG0U=; b=Y6XUTpm8oTnLO89b39GsuTYOac7MSEkTrcFEa7FcVpn2T95qA/S8Z0da3IGqLR0Gfx odvtjB+XfrUUOPcWz9jQ3va+wv0I6j9DHLWUvgJkmoaW5XuTLTS2ciZvBbgRbvO/BmQB 01978NvtJKGz54DWBeQ2qRGlcC+N+TBPrpXb14Y3doVGD86JaoGlZEIGq9C31kfrF9JH NLJ594Bel5ujCsltWhZ/gZvOXnjdv2RESUmqMU2lDDbrdsB5Jd+m15WHAbjMbjsFa04u rfXSxlgXxAsJ1tLxIldEIJou7oG6eZQsln0XQFVE0lULm+m2qjYJ0fZTgO9xSCsgKwJF QGkA== X-Gm-Message-State: AOUpUlG65fa8pEZC07EK3kzQGDisIJaHoijcUhKVAshczn+1rqepbyyf f7AO1Xa7vfGW+ubOrmjzz9B5Kpn2 X-Google-Smtp-Source: AA+uWPyYW+siLaIctoyeGS+fC33L8bzIrc+wKNHpY1lRLRYw1zCiOMNWZQY8iu9dvLgiF+8m1f9D7w== X-Received: by 2002:a62:411a:: with SMTP id o26-v6mr1690568pfa.111.1533714248470; Wed, 08 Aug 2018 00:44:08 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:55 +0530 Message-Id: <1533501842-24503-29-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 08 Aug 2018 07:44:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 08 Aug 2018 07:44:09 +0000 (UTC) for IP:'209.85.210.196' DOMAIN:'mail-pf1-f196.google.com' HELO:'mail-pf1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.210.196 mail-pf1-f196.google.com 209.85.210.196 mail-pf1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 28/35] util: numa: use VIR_AUTOPTR for aggregate types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 08 Aug 2018 07:44:18 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnuma.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 6c6be1c..c1457be 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -57,8 +57,8 @@ char * virNumaGetAutoPlacementAdvice(unsigned short vcpus, unsigned long long balloon) { - virCommandPtr cmd =3D NULL; char *output =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(NUMAD, "-w", NULL); virCommandAddArgFormat(cmd, "%d:%llu", vcpus, @@ -71,7 +71,6 @@ virNumaGetAutoPlacementAdvice(unsigned short vcpus, _("Failed to query numad for the " "advisory nodeset")); =20 - virCommandFree(cmd); return output; } #else /* !HAVE_NUMAD */ @@ -252,41 +251,38 @@ int virNumaGetNodeCPUs(int node, virBitmapPtr *cpus) { + VIR_AUTOPTR(virBitmap) cpumap =3D NULL; VIR_AUTOFREE(unsigned long *) mask =3D NULL; VIR_AUTOFREE(unsigned long *) allonesmask =3D NULL; - virBitmapPtr cpumap =3D NULL; int ncpus =3D 0; int max_n_cpus =3D virNumaGetMaxCPUs(); int mask_n_bytes =3D max_n_cpus / 8; size_t i; - int ret =3D -1; =20 *cpus =3D NULL; =20 if (VIR_ALLOC_N(mask, mask_n_bytes / sizeof(*mask)) < 0) - goto cleanup; + return -1; =20 if (VIR_ALLOC_N(allonesmask, mask_n_bytes / sizeof(*mask)) < 0) - goto cleanup; + return -1; =20 memset(allonesmask, 0xff, mask_n_bytes); =20 /* The first time this returns -1, ENOENT if node doesn't exist... */ if (numa_node_to_cpus(node, mask, mask_n_bytes) < 0) { VIR_WARN("NUMA topology for cell %d is not available, ignoring", n= ode); - ret =3D -2; - goto cleanup; + return -2; } =20 /* second, third... times it returns an all-1's mask */ if (memcmp(mask, allonesmask, mask_n_bytes) =3D=3D 0) { VIR_DEBUG("NUMA topology for cell %d is invalid, ignoring", node); - ret =3D -2; - goto cleanup; + return -2; } =20 if (!(cpumap =3D virBitmapNew(max_n_cpus))) - goto cleanup; + return -1; =20 for (i =3D 0; i < max_n_cpus; i++) { if (MASK_CPU_ISSET(mask, i)) { @@ -295,14 +291,8 @@ virNumaGetNodeCPUs(int node, } } =20 - *cpus =3D cpumap; - cpumap =3D NULL; - ret =3D ncpus; - - cleanup: - virBitmapFree(cpumap); - - return ret; + VIR_STEAL_PTR(*cpus, cpumap); + return ncpus; } # undef MASK_CPU_ISSET # undef n_bits --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714264847757.0506683359512; Wed, 8 Aug 2018 00:44:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04DE065CFC; Wed, 8 Aug 2018 07:44:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A71E3001A65; Wed, 8 Aug 2018 07:44:21 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1C2ED1800BDD; Wed, 8 Aug 2018 07:44:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787iF9i005928 for ; Wed, 8 Aug 2018 03:44:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id D005E27BD1; Wed, 8 Aug 2018 07:44:15 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C3035277D0 for ; Wed, 8 Aug 2018 07:44:12 +0000 (UTC) Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 38E582D1D5 for ; Wed, 8 Aug 2018 07:44:11 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id y10-v6so715419pfn.8 for ; Wed, 08 Aug 2018 00:44:11 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=Thq8OLUUQPp60sfKqBOUqk77DJ+XR1qW0yRh+Ipl8NY=; b=HXl/NsbwH7gKByT/gJXEMIYxsfo4c10qf9PvahJdANYjVMkpB8XzBz6z2xZk1H+kWn sTW5dA1q782rnAwjOMB+5evsf1DrBH+FMm18z8IpbkEmrx2j/HBqMuS8+PGo16eSMnxt isiWUNgS7iBJUM4X09STGF2H84IsnWt19RMStereNZZf7qhxEELKTu6FCBetkX8jL3PN VFb44u96bo7kDWZTKB4THAqtnn6QtGRBeUV7YJVx2RzgDkG7ZHCpLPtkmVv5CYEPrnuk rBzmEmPWg+rm8Sr8C7UKHDQ0KVjSB4zDNDhiQBBkICwMOkU/5oqqlIoh9XsZHdu7OU5A YFvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Thq8OLUUQPp60sfKqBOUqk77DJ+XR1qW0yRh+Ipl8NY=; b=eJ/j4pGK8ADOiaDy+wDrTJrhrg8CBlTtnfCwc9GWi5drL+hvkaFaDF212+Js6rrutH 5nxsgSLF/OL35KREYKrgxZw/I3d7q2azw+0dF3sSCFm2MbBSI/Mjg1R31En5fcTHUqmO fhZ6j80j1Y8pavDWwPbNp+fhF+ooME6794Nnl6YMNSOZBVMqqn+dWE3HQz156Z2Hj7vj vfaulIttPVTOQ7pCtR01NvJKq86Gl1NQPtJ2bHrKNXRH9Q/c0VxEisu0pfaiSqKothAI YMD/OI4QGgo6WU6JpSSFy7MIB7xnIK/B9DpnV70U1tgai4w8tQMrCs6xB50lWP8cDDPH GQ9w== X-Gm-Message-State: AOUpUlG98Ulul6hOAxGBldGP0mqB/ieyYH7WJqkuyYUEPJQCoZYcLOed SKZV9yKPYqBBMIC3wUJobx3btaxt X-Google-Smtp-Source: AA+uWPx/mW72B77kccVIIu+lqeacZcdJUAWUe1KLC31GkGuneMttiVQanD5i98ylTbyd1T+d4HTjnQ== X-Received: by 2002:a65:5304:: with SMTP id m4-v6mr1440560pgq.250.1533714250437; Wed, 08 Aug 2018 00:44:10 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:56 +0530 Message-Id: <1533501842-24503-30-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 08 Aug 2018 07:44:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 08 Aug 2018 07:44:11 +0000 (UTC) for IP:'209.85.210.172' DOMAIN:'mail-pf1-f172.google.com' HELO:'mail-pf1-f172.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.210.172 mail-pf1-f172.google.com 209.85.210.172 mail-pf1-f172.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 29/35] util: perf: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 08 Aug 2018 07:44:23 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virPerfPtr is declared using VIR_AUTOPTR, the function virPerfFree will be run automatically on it when it goes out of scope. This commit also adds an intermediate typedef for virPerf type for use with the cleanup macros. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virperf.c | 3 +-- src/util/virperf.h | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/util/virperf.c b/src/util/virperf.c index 2c832b3..4537cd0 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -26,7 +26,6 @@ #endif =20 #include "virperf.h" -#include "viralloc.h" #include "virerror.h" #include "virlog.h" #include "virfile.h" @@ -61,7 +60,7 @@ struct virPerfEvent { }; typedef struct virPerfEvent *virPerfEventPtr; =20 -struct virPerf { +struct _virPerf { struct virPerfEvent events[VIR_PERF_EVENT_LAST]; }; =20 diff --git a/src/util/virperf.h b/src/util/virperf.h index eee7a03..9d0d5ac 100644 --- a/src/util/virperf.h +++ b/src/util/virperf.h @@ -23,6 +23,7 @@ # define __VIR_PERF_H__ =20 # include "virutil.h" +# include "viralloc.h" =20 /* Some Intel processor families introduced some RDT (Resource Director * Technology) features to monitor or control shared resource based on @@ -62,8 +63,9 @@ typedef enum { =20 VIR_ENUM_DECL(virPerfEvent); =20 -struct virPerf; -typedef struct virPerf *virPerfPtr; +struct _virPerf; +typedef struct _virPerf virPerf; +typedef virPerf *virPerfPtr; =20 virPerfPtr virPerfNew(void); =20 @@ -83,4 +85,6 @@ int virPerfReadEvent(virPerfPtr perf, virPerfEventType type, uint64_t *value); =20 +VIR_DEFINE_AUTOPTR_FUNC(virPerf, virPerfFree) + #endif /* __VIR_PERF_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714282395823.8998143012998; Wed, 8 Aug 2018 00:44:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 884134DAFB; Wed, 8 Aug 2018 07:44:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F0C73001A66; Wed, 8 Aug 2018 07:44:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 04D601800B77; Wed, 8 Aug 2018 07:44:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787iW5q006105 for ; Wed, 8 Aug 2018 03:44:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id AE50B6252C; Wed, 8 Aug 2018 07:44:32 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 727B665F4E for ; Wed, 8 Aug 2018 07:44:14 +0000 (UTC) Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 AA0DC308A95E for ; Wed, 8 Aug 2018 07:44:13 +0000 (UTC) Received: by mail-pg1-f172.google.com with SMTP id r5-v6so703350pgv.0 for ; Wed, 08 Aug 2018 00:44:13 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=d9eP3AHWBICD/LhyVW1QbWjzy4RXsM6/pPWqulwVjBw=; b=DSKOKduCHITfyYuuxPC2KBvx2DhJtj+rI6S8Wb9nciNwm27sq6FZICPy7yUz/c5fO7 j15ZJMdhYxzYdTnZWdJDp5hrl+WMNsskhbWYs6NZM9I1o3gDof1ExfeVCUilsDs20u56 j7zH3pF2IbMD82k/B0Nemsk0UO7myv7H6c5WhOwhKfd46JmdWp6B1+/wyF06KPJfbEjx t5G8b/I/Lx1M9EyEBPMiR4WvOPNkCCvsFYotJIQlxiF4KoV/uVRl1P2sada3VnLW96ue D4W7U8pN6lpfNwtychf7zSy9hnZ7fDRXAqTKNmcG8EFNUO9hFntn/VwXf5WCZxBffLHG 37Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=d9eP3AHWBICD/LhyVW1QbWjzy4RXsM6/pPWqulwVjBw=; b=i6RClM9IwTy1bM0Vujo8WZf6JyxqssIWFhmLiKiJOuLZjv41yUJpmTqKWA/hwEKMA9 vlrZMx/vOFC2Ciupk5khejPvhhjtpaCblHzg5xKFBbJXoKnszi9Yy2u6W9Jjfk1BDy+u qnVI2wqmDg0AU0cfuvgSIPL2cRUB8YRsYBrSHkCO0Twoq/M1YbvpKXuTE+d2eiBchJXA nYf0oUxtUejo5dEx9G6kxoAEAaJvO9oadG3mAgLqJA6smq5a4e09mLLJy3Tn35Ych+5R 2r0cUJPqCBrKhq0RR8ynN47iF9OW9iFeQV5SY7cj8UYsJs22pSJRShB5NUKUSOkK5hE6 bbAg== X-Gm-Message-State: AOUpUlHMZNqInQTgPTaQMmMO3xk5v+3ZqshCeFE2qOgLoEsaESO6/Bw4 ik6dBpWG9Cokuu8Wr9AVFTeJ2DCe X-Google-Smtp-Source: AA+uWPz2kDjOvhzXtRFgDaSqu9Lj75EmtpeWb1W2i2hvixm++/L1CSb+Jw+iMiu6yb5ZTAeI3t2+Sg== X-Received: by 2002:a62:6eca:: with SMTP id j193-v6mr1721784pfc.256.1533714252890; Wed, 08 Aug 2018 00:44:12 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:57 +0530 Message-Id: <1533501842-24503-31-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 08 Aug 2018 07:44:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 08 Aug 2018 07:44:13 +0000 (UTC) for IP:'209.85.215.172' DOMAIN:'mail-pg1-f172.google.com' HELO:'mail-pg1-f172.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.215.172 mail-pg1-f172.google.com 209.85.215.172 mail-pg1-f172.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 30/35] util: perf: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 08 Aug 2018 07:44:41 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virperf.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/util/virperf.c b/src/util/virperf.c index 4537cd0..23f7703 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -175,12 +175,12 @@ typedef struct virPerfEventAttr *virPerfEventAttrPtr; static int virPerfRdtAttrInit(void) { - char *buf =3D NULL; char *tmp =3D NULL; unsigned int attr_type =3D 0; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (virFileReadAllQuiet("/sys/devices/intel_cqm/type", 10, &buf) < 0) - goto error; + return -1; =20 if ((tmp =3D strchr(buf, '\n'))) *tmp =3D '\0'; @@ -188,19 +188,14 @@ virPerfRdtAttrInit(void) if (virStrToLong_ui(buf, NULL, 10, &attr_type) < 0) { virReportSystemError(errno, "%s", _("failed to get rdt event type")); - goto error; + return -1; } - VIR_FREE(buf); =20 attrs[VIR_PERF_EVENT_CMT].attrType =3D attr_type; attrs[VIR_PERF_EVENT_MBMT].attrType =3D attr_type; attrs[VIR_PERF_EVENT_MBML].attrType =3D attr_type; =20 return 0; - - error: - VIR_FREE(buf); - return -1; } =20 =20 @@ -209,7 +204,6 @@ virPerfEventEnable(virPerfPtr perf, virPerfEventType type, pid_t pid) { - char *buf =3D NULL; struct perf_event_attr attr; virPerfEventPtr event =3D &(perf->events[type]); virPerfEventAttrPtr event_attr =3D &attrs[type]; @@ -227,6 +221,8 @@ virPerfEventEnable(virPerfPtr perf, } =20 if (type =3D=3D VIR_PERF_EVENT_CMT) { + VIR_AUTOFREE(char *) buf =3D NULL; + if (virFileReadAll("/sys/devices/intel_cqm/events/llc_occupancy.sc= ale", 10, &buf) < 0) goto error; @@ -236,8 +232,6 @@ virPerfEventEnable(virPerfPtr perf, _("failed to get cmt scaling factor")); goto error; } - - VIR_FREE(buf); } =20 memset(&attr, 0, sizeof(attr)); @@ -268,7 +262,6 @@ virPerfEventEnable(virPerfPtr perf, =20 error: VIR_FORCE_CLOSE(event->fd); - VIR_FREE(buf); return -1; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714273310727.9125892299621; Wed, 8 Aug 2018 00:44:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F49930832DE; Wed, 8 Aug 2018 07:44:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 22B1D608F7; Wed, 8 Aug 2018 07:44:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8A4731800B73; Wed, 8 Aug 2018 07:44:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787iTpp006053 for ; Wed, 8 Aug 2018 03:44:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4451DCBD99; Wed, 8 Aug 2018 07:44:29 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 36598CD64B for ; Wed, 8 Aug 2018 07:44:17 +0000 (UTC) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) (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 01C65307CF26 for ; Wed, 8 Aug 2018 07:44:16 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id e13-v6so716257pff.7 for ; Wed, 08 Aug 2018 00:44:15 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=HUtn7TlRv2FV+bg1J2YD+QjCyEsWGv8kKwX+Anh4EDI=; b=W4EHiG74v2zETNblYJalkfQ41B/2QWchLdyfIIVA5O8FIXR/aZ6E81qZiE60AbXsya MoG4GhPKvdSnCYiVH0Qgl1T1snnHHCp7IGxTHOJblJU+AF+OO0AJpTp4lR7GW+dAl6FF +xRPDb6m3weervIrAYViE8yE+9dU+RUV7xsQa2qn5TFDyeGPhfovG6FbSzAUCREuTYhv l6+TgdzWJD7InP+O7TIb7EmQjIngLq7IMCOELQgUbZkp1rmYI+ruGxHdflEPgHSmOuTM 045/5GwU5GPECcJ/Fi6OxAXV1iHzDBQohrcbM8H4DC5qzSMmqRB/mUzkc08VjwHzmsxQ k9Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=HUtn7TlRv2FV+bg1J2YD+QjCyEsWGv8kKwX+Anh4EDI=; b=Xel2L4QXFO2vmjvqzxfoFSeu9lmknoH9k/XOFK6YUqi5L+FaSWLwcpafWd0gzbWhqK kcna74isATpfHF3JUJ3GzRHwVSD06A8E1rcw3qjzsxxIo198zOgFqX0I+CADs0FhlDFg RDlUUIE+GOH+tQakXjiLeAw3Q1MjmoFZshEXs4VUOnpEXlgiZwfEGZOg+Enqj0Ml4s3x 1UhYYB7zn57R0+F7gFBiDtoCHrIRCljVAbldcakBi29S5QXk+k1yFDGjA7/Ar2xPymDd mIlNuusX5C8yKF6MlG456SZdJiX0y6wdxHwsoO8e4V0zmJ1Ij6ZXXjkhovFKo+vuQtu/ Gekg== X-Gm-Message-State: AOUpUlHwxOzgjAuuAy548xQY7QpWSFFZSGAiBekglEsSFouDzHATo21H w9TYrPe9qMjDmxb7wf0aU1F9fbQb X-Google-Smtp-Source: AA+uWPwvweJyQuIizE5XNRoVfK5PyaE1BRUtwioueKZytc97hmEtJYiRHxkcmeeoP1GzVN3EGxwkYA== X-Received: by 2002:a63:9d47:: with SMTP id i68-v6mr1463916pgd.172.1533714255142; Wed, 08 Aug 2018 00:44:15 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:58 +0530 Message-Id: <1533501842-24503-32-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:44:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:44:16 +0000 (UTC) for IP:'209.85.210.195' DOMAIN:'mail-pf1-f195.google.com' HELO:'mail-pf1-f195.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.210.195 mail-pf1-f195.google.com 209.85.210.195 mail-pf1-f195.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 31/35] util: pidfile: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 08 Aug 2018 07:44:32 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virpidfile.c | 186 ++++++++++++++++------------------------------= ---- 1 file changed, 60 insertions(+), 126 deletions(-) diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index 1a85d43..999bccb 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -97,29 +97,18 @@ int virPidFileWrite(const char *dir, const char *name, pid_t pid) { - int rc; - char *pidfile =3D NULL; + VIR_AUTOFREE(char *) pidfile =3D NULL; =20 - if (name =3D=3D NULL || dir =3D=3D NULL) { - rc =3D -EINVAL; - goto cleanup; - } + if (name =3D=3D NULL || dir =3D=3D NULL) + return -EINVAL; =20 - if (virFileMakePath(dir) < 0) { - rc =3D -errno; - goto cleanup; - } + if (virFileMakePath(dir) < 0) + return -errno; =20 - if (!(pidfile =3D virPidFileBuildPath(dir, name))) { - rc =3D -ENOMEM; - goto cleanup; - } + if (!(pidfile =3D virPidFileBuildPath(dir, name))) + return -ENOMEM; =20 - rc =3D virPidFileWritePath(pidfile, pid); - - cleanup: - VIR_FREE(pidfile); - return rc; + return virPidFileWritePath(pidfile, pid); } =20 =20 @@ -170,25 +159,17 @@ int virPidFileRead(const char *dir, const char *name, pid_t *pid) { - int rc; - char *pidfile =3D NULL; + VIR_AUTOFREE(char *) pidfile =3D NULL; + *pid =3D 0; =20 - if (name =3D=3D NULL || dir =3D=3D NULL) { - rc =3D -EINVAL; - goto cleanup; - } + if (name =3D=3D NULL || dir =3D=3D NULL) + return -EINVAL; =20 - if (!(pidfile =3D virPidFileBuildPath(dir, name))) { - rc =3D -ENOMEM; - goto cleanup; - } + if (!(pidfile =3D virPidFileBuildPath(dir, name))) + return -ENOMEM; =20 - rc =3D virPidFileReadPath(pidfile, pid); - - cleanup: - VIR_FREE(pidfile); - return rc; + return virPidFileReadPath(pidfile, pid); } =20 =20 @@ -219,20 +200,20 @@ int virPidFileReadPathIfAlive(const char *path, { int ret; bool isLink; - char *procPath =3D NULL; - char *procLink =3D NULL; size_t procLinkLen; - char *resolvedBinPath =3D NULL; - char *resolvedProcLink =3D NULL; const char deletedText[] =3D " (deleted)"; size_t deletedTextLen =3D strlen(deletedText); pid_t retPid; + VIR_AUTOFREE(char *) procPath =3D NULL; + VIR_AUTOFREE(char *) procLink =3D NULL; + VIR_AUTOFREE(char *) resolvedBinPath =3D NULL; + VIR_AUTOFREE(char *) resolvedProcLink =3D NULL; =20 /* only set this at the very end on success */ *pid =3D -1; =20 if ((ret =3D virPidFileReadPath(path, &retPid)) < 0) - goto cleanup; + return ret; =20 #ifndef WIN32 /* Check that it's still alive. Safe to skip this sanity check on @@ -252,13 +233,12 @@ int virPidFileReadPathIfAlive(const char *path, goto cleanup; } =20 - if (virAsprintf(&procPath, "/proc/%lld/exe", (long long)retPid) < 0) { - ret =3D -ENOMEM; - goto cleanup; - } + if (virAsprintf(&procPath, "/proc/%lld/exe", (long long)retPid) < 0) + return -ENOMEM; =20 if ((ret =3D virFileIsLink(procPath)) < 0) - goto cleanup; + return ret; + isLink =3D ret; =20 if (isLink && virFileLinkPointsTo(procPath, binPath)) { @@ -275,27 +255,21 @@ int virPidFileReadPathIfAlive(const char *path, * "$procpath (deleted)". Read that link, remove the " (deleted)" * part, and see if it has the same canonicalized name as binpath. */ - if (!(procLink =3D areadlink(procPath))) { - ret =3D -errno; - goto cleanup; - } + if (!(procLink =3D areadlink(procPath))) + return -errno; + procLinkLen =3D strlen(procLink); if (procLinkLen > deletedTextLen) procLink[procLinkLen - deletedTextLen] =3D 0; =20 if ((ret =3D virFileResolveAllLinks(binPath, &resolvedBinPath)) < 0) - goto cleanup; + return ret; if ((ret =3D virFileResolveAllLinks(procLink, &resolvedProcLink)) < 0) - goto cleanup; + return ret; =20 ret =3D STREQ(resolvedBinPath, resolvedProcLink) ? 0 : -1; =20 cleanup: - VIR_FREE(procPath); - VIR_FREE(procLink); - VIR_FREE(resolvedProcLink); - VIR_FREE(resolvedBinPath); - /* return the originally set pid of -1 unless we proclaim success */ if (ret =3D=3D 0) *pid =3D retPid; @@ -326,24 +300,15 @@ int virPidFileReadIfAlive(const char *dir, pid_t *pid, const char *binpath) { - int rc =3D 0; - char *pidfile =3D NULL; + VIR_AUTOFREE(char *) pidfile =3D NULL; =20 - if (name =3D=3D NULL || dir =3D=3D NULL) { - rc =3D -EINVAL; - goto cleanup; - } + if (name =3D=3D NULL || dir =3D=3D NULL) + return -EINVAL; =20 - if (!(pidfile =3D virPidFileBuildPath(dir, name))) { - rc =3D -ENOMEM; - goto cleanup; - } + if (!(pidfile =3D virPidFileBuildPath(dir, name))) + return -ENOMEM; =20 - rc =3D virPidFileReadPathIfAlive(pidfile, pid, binpath); - - cleanup: - VIR_FREE(pidfile); - return rc; + return virPidFileReadPathIfAlive(pidfile, pid, binpath); } =20 =20 @@ -361,24 +326,15 @@ int virPidFileDeletePath(const char *pidfile) int virPidFileDelete(const char *dir, const char *name) { - int rc =3D 0; - char *pidfile =3D NULL; + VIR_AUTOFREE(char *) pidfile =3D NULL; =20 - if (name =3D=3D NULL || dir =3D=3D NULL) { - rc =3D -EINVAL; - goto cleanup; - } + if (name =3D=3D NULL || dir =3D=3D NULL) + return -EINVAL; =20 - if (!(pidfile =3D virPidFileBuildPath(dir, name))) { - rc =3D -ENOMEM; - goto cleanup; - } + if (!(pidfile =3D virPidFileBuildPath(dir, name))) + return -ENOMEM; =20 - rc =3D virPidFileDeletePath(pidfile); - - cleanup: - VIR_FREE(pidfile); - return rc; + return virPidFileDeletePath(pidfile); } =20 int virPidFileAcquirePath(const char *path, @@ -470,24 +426,15 @@ int virPidFileAcquire(const char *dir, bool waitForLock, pid_t pid) { - int rc =3D 0; - char *pidfile =3D NULL; + VIR_AUTOFREE(char *) pidfile =3D NULL; =20 - if (name =3D=3D NULL || dir =3D=3D NULL) { - rc =3D -EINVAL; - goto cleanup; - } + if (name =3D=3D NULL || dir =3D=3D NULL) + return -EINVAL; =20 - if (!(pidfile =3D virPidFileBuildPath(dir, name))) { - rc =3D -ENOMEM; - goto cleanup; - } + if (!(pidfile =3D virPidFileBuildPath(dir, name))) + return -ENOMEM; =20 - rc =3D virPidFileAcquirePath(pidfile, waitForLock, pid); - - cleanup: - VIR_FREE(pidfile); - return rc; + return virPidFileAcquirePath(pidfile, waitForLock, pid); } =20 =20 @@ -518,24 +465,15 @@ int virPidFileRelease(const char *dir, const char *name, int fd) { - int rc =3D 0; - char *pidfile =3D NULL; + VIR_AUTOFREE(char *) pidfile =3D NULL; =20 - if (name =3D=3D NULL || dir =3D=3D NULL) { - rc =3D -EINVAL; - goto cleanup; - } + if (name =3D=3D NULL || dir =3D=3D NULL) + return -EINVAL; =20 - if (!(pidfile =3D virPidFileBuildPath(dir, name))) { - rc =3D -ENOMEM; - goto cleanup; - } + if (!(pidfile =3D virPidFileBuildPath(dir, name))) + return -ENOMEM; =20 - rc =3D virPidFileReleasePath(pidfile, fd); - - cleanup: - VIR_FREE(pidfile); - return rc; + return virPidFileReleasePath(pidfile, fd); } =20 =20 @@ -545,8 +483,7 @@ virPidFileConstructPath(bool privileged, const char *progname, char **pidfile) { - int ret =3D -1; - char *rundir =3D NULL; + VIR_AUTOFREE(char *) rundir =3D NULL; =20 if (privileged) { /* @@ -556,29 +493,26 @@ virPidFileConstructPath(bool privileged, if (!statedir) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("No statedir specified")); - goto cleanup; + return -1; } if (virAsprintf(pidfile, "%s/run/%s.pid", statedir, progname) < 0) - goto cleanup; + return -1; } else { if (!(rundir =3D virGetUserRuntimeDirectory())) - goto cleanup; + return -1; =20 if (virFileMakePathWithMode(rundir, 0700) < 0) { virReportSystemError(errno, _("Cannot create user runtime directory '= %s'"), rundir); - goto cleanup; + return -1; } =20 if (virAsprintf(pidfile, "%s/%s.pid", rundir, progname) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(rundir); - return ret; + return 0; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714277636879.6288116486503; Wed, 8 Aug 2018 00:44:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6EE341B7F; Wed, 8 Aug 2018 07:44:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2A4B33001A65; Wed, 8 Aug 2018 07:44:35 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B351B24602; Wed, 8 Aug 2018 07:44:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787iThR006058 for ; Wed, 8 Aug 2018 03:44:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4E11ACBD6B; Wed, 8 Aug 2018 07:44:29 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3CEC0CD6AB for ; Wed, 8 Aug 2018 07:44:19 +0000 (UTC) Received: from mail-pl0-f47.google.com (mail-pl0-f47.google.com [209.85.160.47]) (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 F1D3430820E4 for ; Wed, 8 Aug 2018 07:44:17 +0000 (UTC) Received: by mail-pl0-f47.google.com with SMTP id g6-v6so655009plq.9 for ; Wed, 08 Aug 2018 00:44:17 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=6/T5fx/nOf0Nfb0EKHp82mo0Bc+N6MYHKYHXZ5Qqc4o=; b=tB3hRQDSqHlsJthewXXuk2+FU2Zeccdub86u19jBsRmB919f9ezx1QRTSu122dyIsv eHi67kzGgp4jE6v0/gYJUe4iOsm+JIY1t50iCZSGRHoBN5l6vB66FcvRdrhsAvcVBJO3 mO5M/HytmceqBdoElV2iSg/eJmwCmUkZz5RCdo2g18yQTsrV055OpY7aOZF0MAoqWdLB e66RxwKbFJZBxKhwfstPjh7u1rDaHQZ5pC+orL/HkBk5Ojj25XWmLOQbIKmEu5Dx+z+C AAR1uvUnrf2wfHa8NVJItCcVxMII+BPvrpRpdzqfQSCxfxV7OwW/3fJ4XKUQSdXok0i9 yJQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=6/T5fx/nOf0Nfb0EKHp82mo0Bc+N6MYHKYHXZ5Qqc4o=; b=uQnevJPZAD7D5MIe0YLn04fziCdpohxeteD035m42W92nXgwHA/kTT1CImL/a1KxLq rUkGvk83In4fdn3XGNcA8bFemNDIThG+c3z6VPnYk34DoEwNfGNKzVRO7H0hMAuMgwta mgr3dfjlHHlwGJ33L72JNr3KVc+svJhtK0R+VaAMNcj2qOfJqboreqnaqN9V45baML9Z xcDOYnJDLcec6qyAAcyS+SIG04SURoTrpCjach8P0KX59If7qgMQ9f0e1TBlQXAcm8su hzoCaaehwezlPT2nwsY+vbFOzdcefGX1bn2qpJMMF1/CwccRYvUgAHuF6gS2HZzUN+wO yFZg== X-Gm-Message-State: AOUpUlGtLwTkewrEQkhbE85KUE4H1aJ3iUsO0T3TgyQxa4PG2he58wCA +ey5GQVFMkuRnWAsoomBoftCoMFm X-Google-Smtp-Source: AA+uWPym7F5Kna6y9y6EbOwRTOSZhYierizHtOh2aLwMBQF/JxwNmDe5kq5ZaxxX5S/qPJj6JtMoPw== X-Received: by 2002:a17:902:2f84:: with SMTP id t4-v6mr1492111plb.87.1533714257194; Wed, 08 Aug 2018 00:44:17 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:59 +0530 Message-Id: <1533501842-24503-33-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 08 Aug 2018 07:44:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 08 Aug 2018 07:44:18 +0000 (UTC) for IP:'209.85.160.47' DOMAIN:'mail-pl0-f47.google.com' HELO:'mail-pl0-f47.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.160.47 mail-pl0-f47.google.com 209.85.160.47 mail-pl0-f47.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 32/35] util: process: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 08 Aug 2018 07:44:36 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virprocess.c | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index f92b0dc..215e05d 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -158,7 +158,7 @@ virProcessAbort(pid_t pid) int saved_errno; int ret; int status; - char *tmp =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (pid <=3D 0) return; @@ -199,7 +199,6 @@ virProcessAbort(pid_t pid) VIR_DEBUG("failed to reap child %lld, abandoning it", (long long) pid); =20 cleanup: - VIR_FREE(tmp); errno =3D saved_errno; } #else @@ -238,6 +237,7 @@ virProcessWait(pid_t pid, int *exitstatus, bool raw) { int ret; int status; + VIR_AUTOFREE(char *) st =3D NULL; =20 if (pid <=3D 0) { if (pid !=3D -1) @@ -270,13 +270,10 @@ virProcessWait(pid_t pid, int *exitstatus, bool raw) return 0; =20 error: - { - char *st =3D virProcessTranslateStatus(status); - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Child process (%lld) unexpected %s"), - (long long) pid, NULLSTR(st)); - VIR_FREE(st); - } + st =3D virProcessTranslateStatus(status); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Child process (%lld) unexpected %s"), + (long long) pid, NULLSTR(st)); return -1; } =20 @@ -603,7 +600,7 @@ virProcessGetAffinity(pid_t pid ATTRIBUTE_UNUSED) int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids) { int ret =3D -1; - char *taskPath =3D NULL; + VIR_AUTOFREE(char *) taskPath =3D NULL; DIR *dir =3D NULL; int value; struct dirent *ent; @@ -636,7 +633,6 @@ int virProcessGetPids(pid_t pid, size_t *npids, pid_t *= *pids) =20 cleanup: VIR_DIR_CLOSE(dir); - VIR_FREE(taskPath); if (ret < 0) VIR_FREE(*pids); return ret; @@ -648,7 +644,6 @@ int virProcessGetNamespaces(pid_t pid, int **fdlist) { int ret =3D -1; - char *nsfile =3D NULL; size_t i =3D 0; const char *ns[] =3D { "user", "ipc", "uts", "net", "pid", "mnt" }; =20 @@ -656,6 +651,7 @@ int virProcessGetNamespaces(pid_t pid, *fdlist =3D NULL; =20 for (i =3D 0; i < ARRAY_CARDINALITY(ns); i++) { + VIR_AUTOFREE(char *) nsfile =3D NULL; int fd; =20 if (virAsprintf(&nsfile, "/proc/%llu/ns/%s", @@ -671,14 +667,11 @@ int virProcessGetNamespaces(pid_t pid, =20 (*fdlist)[(*nfdlist)-1] =3D fd; } - - VIR_FREE(nsfile); } =20 ret =3D 0; =20 cleanup: - VIR_FREE(nsfile); if (ret < 0) { for (i =3D 0; i < *nfdlist; i++) VIR_FORCE_CLOSE((*fdlist)[i]); @@ -977,12 +970,12 @@ virProcessSetMaxCoreSize(pid_t pid ATTRIBUTE_UNUSED, int virProcessGetStartTime(pid_t pid, unsigned long long *timestamp) { - char *filename =3D NULL; - char *buf =3D NULL; char *tmp; int ret =3D -1; int len; char **tokens =3D NULL; + VIR_AUTOFREE(char *) filename =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (virAsprintf(&filename, "/proc/%llu/stat", (long long) pid) < 0) return -1; @@ -1032,8 +1025,6 @@ int virProcessGetStartTime(pid_t pid, =20 cleanup: virStringListFree(tokens); - VIR_FREE(filename); - VIR_FREE(buf); return ret; } #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) @@ -1080,7 +1071,7 @@ static int virProcessNamespaceHelper(int errfd, virProcessNamespaceCallback cb, void *opaque) { - char *path; + VIR_AUTOFREE(char *) path =3D NULL; int fd =3D -1; int ret =3D -1; =20 @@ -1109,7 +1100,6 @@ static int virProcessNamespaceHelper(int errfd, ignore_value(safewrite(errfd, err->message, len)); } } - VIR_FREE(path); VIR_FORCE_CLOSE(fd); return ret; } @@ -1145,7 +1135,7 @@ virProcessRunInMountNamespace(pid_t pid, VIR_FORCE_CLOSE(errfd[1]); _exit(ret < 0 ? EXIT_CANCELED : ret); } else { - char *buf =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; int status; =20 VIR_FORCE_CLOSE(errfd[1]); @@ -1159,7 +1149,6 @@ virProcessRunInMountNamespace(pid_t pid, NULLSTR(buf)); } } - VIR_FREE(buf); } =20 cleanup: @@ -1226,7 +1215,7 @@ virProcessNamespaceAvailable(unsigned int ns) int flags =3D 0; int cpid; char *childStack; - char *stack; + VIR_AUTOFREE(char *)stack =3D NULL; int stacksize =3D getpagesize() * 4; =20 if (ns & VIR_PROCESS_NAMESPACE_MNT) @@ -1251,7 +1240,7 @@ virProcessNamespaceAvailable(unsigned int ns) childStack =3D stack + stacksize; =20 cpid =3D clone(virProcessDummyChild, childStack, flags, NULL); - VIR_FREE(stack); + if (cpid < 0) { char ebuf[1024] ATTRIBUTE_UNUSED; VIR_DEBUG("clone call returned %s, container support is not enable= d", --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714292025236.11584790554684; Wed, 8 Aug 2018 00:44:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1FABB80F75; Wed, 8 Aug 2018 07:44:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7EE26886A; Wed, 8 Aug 2018 07:44:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BD573245FF; Wed, 8 Aug 2018 07:44:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787ilRb006270 for ; Wed, 8 Aug 2018 03:44:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 372CB6090D; Wed, 8 Aug 2018 07:44:47 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C7CB6090B for ; Wed, 8 Aug 2018 07:44:20 +0000 (UTC) Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 0B1B781DF6 for ; Wed, 8 Aug 2018 07:44:20 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id f14-v6so674186pgv.13 for ; Wed, 08 Aug 2018 00:44:20 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=h5F/rhXLq8rzyLRwgvu7H5wo1Wz8Vz/l+4Qd7RpGrgA=; b=kEwwqYDC74SZN580ewdt1fZjRNmXF0XpY1duif+Qj6pWnUMjgzRQdNGDgF1/sDIIDW Qrpe1ZoFFG3Lsa+AOegv1VWwmDTerUe2gPa75ts77g0OEaoJpgDtlwD2gLkny/rCwzvn af5v+9uOLuoWR6M8Vs4Ee/fA7ULhYWkWFvvVuQmeLO1ColGzjnyVKThnitAamMoUfJwF 9Gr7Hbldo+JpEzKLJg2vMHxvMiEo3/TNsdVCbVvokyRVd79SBp1opQ+2FmV2nfpBS+Ed hodDkyXCh9o8XJvtKtL3KnqyPt/TftBDOoaeDnww1lTFop3OU7A2nwkXU7ry7l+wvZ+m gsiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=h5F/rhXLq8rzyLRwgvu7H5wo1Wz8Vz/l+4Qd7RpGrgA=; b=PEM2Rc69NGr+9yWfr5tCxlnY3yn210TjI7If1LUH1c5TEDCqL0ikSW/KPMgk7bsjVt 0nSJRkgxMGQ8/vFWV7SCryIyf30R6cCCZopfg/e1eH6ZaL5DGScHUSsdwGdwi1a6/d6G SZxyUctsC8QV+XFIDCm4hryRTScKZpOG9e97dKKSx/lM8/D6OWClXBeNxgw60wFgwWLt B2MmUVHtN7zjlTjah79PiwMymFgruNzmixgBiLH5tYEk4dePsckpeN+8PbOAaeh+GeHW 1Sn7NAuctl5vyYUVz+dH0gdlsBBUAQM+ZPM2/GKU4LqUfs5EUXeP9sTSaI78X1flQ78S OE4w== X-Gm-Message-State: AOUpUlGOg4BK0MMG9oY0yNFZI6MJiy65waOuG3D82OaUjw7URLQP9I74 Lt5isY7cPenv8e5evRpG9OYy52v1 X-Google-Smtp-Source: AA+uWPySOPraq5kTLTIkjVhBDIKP8AVGMROWRxJufZv3Tjoy/E4xvVMjagjQqRlB6tm1B8ZE+8Wszg== X-Received: by 2002:a63:5421:: with SMTP id i33-v6mr1473408pgb.417.1533714259267; Wed, 08 Aug 2018 00:44:19 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:14:00 +0530 Message-Id: <1533501842-24503-34-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 08 Aug 2018 07:44:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 08 Aug 2018 07:44:20 +0000 (UTC) for IP:'209.85.215.174' DOMAIN:'mail-pg1-f174.google.com' HELO:'mail-pg1-f174.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.215.174 mail-pg1-f174.google.com 209.85.215.174 mail-pg1-f174.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 33/35] util: process: use VIR_AUTOPTR for aggregate types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 08 Aug 2018 07:44:50 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virprocess.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 215e05d..1fbbe0c 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -971,9 +971,8 @@ int virProcessGetStartTime(pid_t pid, unsigned long long *timestamp) { char *tmp; - int ret =3D -1; int len; - char **tokens =3D NULL; + VIR_AUTOPTR(virString) tokens =3D NULL; VIR_AUTOFREE(char *) filename =3D NULL; VIR_AUTOFREE(char *) buf =3D NULL; =20 @@ -981,7 +980,7 @@ int virProcessGetStartTime(pid_t pid, return -1; =20 if ((len =3D virFileReadAll(filename, 1024, &buf)) < 0) - goto cleanup; + return -1; =20 /* start time is the token at index 19 after the '(process name)' entr= y - since only this * field can contain the ')' character, search backwards for this to a= void malicious @@ -992,14 +991,14 @@ int virProcessGetStartTime(pid_t pid, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find start time in %s"), filename); - goto cleanup; + return -1; } tmp +=3D 2; /* skip ') ' */ if ((tmp - buf) >=3D len) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find start time in %s"), filename); - goto cleanup; + return -1; } =20 tokens =3D virStringSplit(tmp, " ", 0); @@ -1008,7 +1007,7 @@ int virProcessGetStartTime(pid_t pid, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find start time in %s"), filename); - goto cleanup; + return -1; } =20 if (virStrToLong_ull(tokens[19], @@ -1018,14 +1017,10 @@ int virProcessGetStartTime(pid_t pid, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot parse start time %s in %s"), tokens[19], filename); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - virStringListFree(tokens); - return ret; + return 0; } #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) int virProcessGetStartTime(pid_t pid, --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714270686429.0529577470843; Wed, 8 Aug 2018 00:44:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D9F03150088; Wed, 8 Aug 2018 07:44:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0EABD65F41; Wed, 8 Aug 2018 07:44:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B31EA24B77; Wed, 8 Aug 2018 07:44:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787iPGZ006013 for ; Wed, 8 Aug 2018 03:44:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id DBFBF10694EC; Wed, 8 Aug 2018 07:44:25 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B6D0F1062246 for ; Wed, 8 Aug 2018 07:44:23 +0000 (UTC) Received: from mail-pl0-f51.google.com (mail-pl0-f51.google.com [209.85.160.51]) (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 DBBD3D5531 for ; Wed, 8 Aug 2018 07:44:21 +0000 (UTC) Received: by mail-pl0-f51.google.com with SMTP id t17-v6so649287ply.13 for ; Wed, 08 Aug 2018 00:44:21 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=0uu1wqr/HeAWRNMDbQN3It67Fu0wXBTg5/FMZPnT4sk=; b=ibfkK3/L9lBNe67DDvFIiit9nQR8kQ0fkPBfJQR5eDWu/wNeZOBUP2WCRo8IBzJidO cmDsMfl+JA5lKxNaNH/yDZY7Sx4gpAJTfKMa/7+xTAAklacq1sg3IozCPHIueKTJCyxg M5cdWdwpu8MRISaNRIoE5YFQQyBVsSHMK6yj3YJp9bVACG06nBYcBaT8LL39JIVDvFsV wpNPF+D6LfCErErvOM86RgwlfDENHmezKvp3Kn+pjDFXlFEkkiJd1DqCbi6AXvPfGVOk RRJ3lwKt3CWmMCcz9SrlNFZNq/1NQZYkA+1dKZmWohdZ5fk+Twq0zyp5DxkV+asB1NCQ TQNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=0uu1wqr/HeAWRNMDbQN3It67Fu0wXBTg5/FMZPnT4sk=; b=XOPERh2qOMUXkdhXG5btBUHm/5jFdiutxuhvLVP07UxwLbapLBPyPajNmz8XAknrdJ r+uI3O2oty1zJfYG+jI/kZPQ4cYR4k20AzIqJ2rB+zpSlc3YMZPRVQpN7jWJnymZe44O S2l5mqkijqF4zqpX6sx3zLIHdZIUO8zh7Mx4GCk+BwLelN1ZHgnLpjYMuc89q0Nxy1LL x4CqkzcjhfFrDJ1162GdX1kO80J+N9MJgwk8l96g+CVgb34TNbuQCdqyCowOr0+F+B6f HQ5yPXAQAAjGoeSnG1ieePuFUK2Om+2Uxpa+iZZpk3Hv+KO6gfvgHD5ip/ame1v6zu02 7gHg== X-Gm-Message-State: AOUpUlGtR/jPk8/A4l10D0icBkRqzN2tdmpYvftD2x8TWY0FIcg2mL8n ZEuSX0jXUyhTIlV+ZXzfRorsEGOs X-Google-Smtp-Source: AA+uWPwv9qmOJbmLpmseqEc5k60pgjERYIomjwxCjJyfJMJwz0ILTuiLLAvSukpuB/GfDLF5BjUwWw== X-Received: by 2002:a17:902:403:: with SMTP id 3-v6mr1542890ple.39.1533714261154; Wed, 08 Aug 2018 00:44:21 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:14:01 +0530 Message-Id: <1533501842-24503-35-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 08 Aug 2018 07:44:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 08 Aug 2018 07:44:22 +0000 (UTC) for IP:'209.85.160.51' DOMAIN:'mail-pl0-f51.google.com' HELO:'mail-pl0-f51.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.160.51 mail-pl0-f51.google.com 209.85.160.51 mail-pl0-f51.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 34/35] util: qemu: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 08 Aug 2018 07:44:28 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virqemu.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 30b8dc1..4089b8e 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -85,29 +85,22 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *ke= y, virBufferPtr buf) { virJSONValuePtr member; - char *prefix =3D NULL; size_t i; - int ret =3D 0; =20 for (i =3D 0; i < virJSONValueArraySize(array); i++) { + VIR_AUTOFREE(char *) prefix =3D NULL; member =3D virJSONValueArrayGet((virJSONValuePtr) array, i); =20 if (virAsprintf(&prefix, "%s.%zu", key, i) < 0) - goto cleanup; + return 0; =20 if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, virQEMUBuildCommandLineJSON= ArrayNumbered, true) < 0) - goto cleanup; - - VIR_FREE(prefix); + return 0; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(prefix); - return ret; + return 0; } =20 =20 @@ -118,23 +111,18 @@ virQEMUBuildCommandLineJSONIterate(const char *key, void *opaque) { struct virQEMUCommandLineJSONIteratorData *data =3D opaque; - char *tmpkey =3D NULL; - int ret =3D -1; =20 if (data->prefix) { + VIR_AUTOFREE(char *) tmpkey =3D NULL; if (virAsprintf(&tmpkey, "%s.%s", data->prefix, key) < 0) return -1; =20 - ret =3D virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->bu= f, + return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf, data->arrayFunc, false); - - VIR_FREE(tmpkey); } else { - ret =3D virQEMUBuildCommandLineJSONRecurse(key, value, data->buf, + return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf, data->arrayFunc, false); } - - return ret; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 03:28:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714275253946.7356345965004; Wed, 8 Aug 2018 00:44:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 49F5E307D871; Wed, 8 Aug 2018 07:44:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 170942010D0C; Wed, 8 Aug 2018 07:44:33 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BC92A1800B74; Wed, 8 Aug 2018 07:44:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787iUtt006069 for ; Wed, 8 Aug 2018 03:44:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id E83CE1ACAF; Wed, 8 Aug 2018 07:44:30 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D563B18429 for ; Wed, 8 Aug 2018 07:44:24 +0000 (UTC) Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) (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 E998230B8F84 for ; Wed, 8 Aug 2018 07:44:23 +0000 (UTC) Received: by mail-pl0-f67.google.com with SMTP id u11-v6so662965plq.5 for ; Wed, 08 Aug 2018 00:44:23 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=yFTFE2mz9b7IuFmRQATimspge1dqcjZlUeUJBSrPv8I=; b=ixQt0/5hhzfqG7OhYB4AInSfCO70+y5QRtT1ZlIJgoIBKh81eWV1Idfr4RjVxsoBHZ +KiO1zzxN922nJT2hVB3obkwltdlJje9ujj73mkXug74FlIrsBQC6Vr2Opy5dx2obArz CXrpOiZfPdHsLf/+Jp4063M84kLOzbV1TqhqQhMXkVy2tsCmSBaUgWPwAXGwKuX/7lbp uHu1EpqR3HL/ld8xgGSFr1Qjq00tfeogy9oE7J4EfVR84sshmVVBOod7tQoTRahRPPlx 29Efo6jh5DhR8qeIX4up3hn2XMDN7xM6275z1/+B5NxY7ltadT64y/oOjLWy5NM0f6XL 6ghQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=yFTFE2mz9b7IuFmRQATimspge1dqcjZlUeUJBSrPv8I=; b=Rtz5AUaWcDpNcem37/3a4C+CU7wrAUF2ivk6JiO7zE0rcAeK+/d5UE4cwtCC4hRs1Z HAcFrMZY7PZlpPDvWUYt/a2RFkr4LTMRwVWISWDn41G8v15exDl5NPLHE+zY1dF1Ljnc 6AVmlrTLGZ+a/Nhdjqc8vK0b5/sOh2rImlyNrVhTbsgPey7TdLr2UlNKyRVCBiGlb5/h wI8QcxMI143V0mY6nv158tqPKHG82z71bY7fC5Mca9As1+dcl9sIBfZS71J6cG4+jqFO /1N4w10Nzf77udjzUqORv40vWpU0bckO8nQzEgRw+Atc+RXBqMuBwqwChtq2c9Y1O6cJ dwNg== X-Gm-Message-State: AOUpUlEP/QBM7Y/O7O9mUu87URaEtpE9H02SGSJnoiz24TSFyA9frmCL zYJnCGXt6Kkiy2teNSWZaKgAXvnn X-Google-Smtp-Source: AA+uWPy7nA6nIudRKijEXVKb4lXlkEF5gqYOjLKH0dv8rjdFAzmJG/v2CRvwJcgIDp8wSBcBIHbKow== X-Received: by 2002:a17:902:6684:: with SMTP id e4-v6mr1509585plk.35.1533714263222; Wed, 08 Aug 2018 00:44:23 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:14:02 +0530 Message-Id: <1533501842-24503-36-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 08 Aug 2018 07:44:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 08 Aug 2018 07:44:24 +0000 (UTC) for IP:'209.85.160.67' DOMAIN:'mail-pl0-f67.google.com' HELO:'mail-pl0-f67.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.160.67 mail-pl0-f67.google.com 209.85.160.67 mail-pl0-f67.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 35/35] util: qemu: use VIR_AUTOPTR for aggregate types 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 08 Aug 2018 07:44:34 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virqemu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 4089b8e..bb88f49 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -56,7 +56,7 @@ virQEMUBuildCommandLineJSONArrayBitmap(const char *key, { ssize_t pos =3D -1; ssize_t end; - virBitmapPtr bitmap =3D NULL; + VIR_AUTOPTR(virBitmap) bitmap =3D NULL; =20 if (virJSONValueGetArrayAsBitmap(array, &bitmap) < 0) return -1; @@ -73,8 +73,6 @@ virQEMUBuildCommandLineJSONArrayBitmap(const char *key, } } =20 - virBitmapFree(bitmap); - return 0; } =20 @@ -282,6 +280,7 @@ virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr sr= cdef) cleanup: virBufferFreeAndReset(&buf); return ret; + } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list