From nobody Sun Feb 8 07:07:42 2026 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 1532806896708756.8770353864485; Sat, 28 Jul 2018 12:41:36 -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 EB41B3084047; Sat, 28 Jul 2018 19:41: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 A4F283001A45; Sat, 28 Jul 2018 19:41: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 450321800B6C; Sat, 28 Jul 2018 19:41:34 +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 w6SJfNIR020947 for ; Sat, 28 Jul 2018 15:41:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id D30992010CE7; Sat, 28 Jul 2018 19:41: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 C30882010CE6 for ; Sat, 28 Jul 2018 19:41:23 +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 4111B307D84A for ; Sat, 28 Jul 2018 19:41:22 +0000 (UTC) Received: by mail-pl0-f47.google.com with SMTP id m1-v6so3726602plt.6 for ; Sat, 28 Jul 2018 12:41:22 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41: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=uYJsWhM7Hi+O34SBFM1Gugs+RwkrpM6nhIwUc3lp2XY=; b=GE7YSh8OikTGEPTesg5dQftIlSZshaF9Sx1mK0GuguHc8Wke7AH+sRpo3S1sPe4har BUUQBtf6Uwv0uMVElNBpRkujYwgBRfhNRAfIi92pXNw99rInaxuUAIiKp7U16oWhKeNA HuR6dq2rj2vt1fhbEYofYUFXjZ5gbhHuRKBkCpkPy5v9dlb4vmM4P76Ks4z6kWPQjap1 lxilYLJcNllBzej1rfLJf87jcmuTr6RMOZFlzADlxoJKVmBaKTAXctwDcMkse+ELun8Q iCfiOb7dxlQLgS89F6odU1KqZv8Wdzc9QNnIz/Ye40ybggzji2yB76H8QlODrd6Yc+Tl lZhw== 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=uYJsWhM7Hi+O34SBFM1Gugs+RwkrpM6nhIwUc3lp2XY=; b=bpUmyVqEU9y6WVoRg95hss47teLTTKYPwdQsmzQIuQjOMg/1bbUORt4sPU2Gn1r5eh Ps/3cy//WyWHIMSFuMo3EACBTJvoC1SCkx6oOUXqT5s8xA1UFolCRjY4ihefRFsnD3q/ 2RKaETKwcXRh4QHDnXZovvTG8iAFDd2Ys8aNaCw4SEi9tcRO/NiWpSUCBUTWtFEKjrPY OjN3iH8KOVGn7B1Es13sD9viZdZ2bLIphU9n15pnPdZ4EueOJhk4FkYR/YKcM2YN0GCW daqNWxODc9P6DwSYUbWWYnYMB1wIzkvbqEhYY+Z2NcjzJ0LGhz1DxmgRBOqhxeFl7O4h VOZw== X-Gm-Message-State: AOUpUlHp0uE91sFyixTaQHkyaofYJ6X6V1c96ZU1F7pRbgIJ0QtWLSQs LGvNPOTKqIZFvpyL0d58MTKPa1gB X-Google-Smtp-Source: AAOMgpf9j9TrPaXHn1oOGWBCrnZUFE3NKeYPdK35nyhkLXBwpN25keu+beepy3SPfFFGuGuVQvfFNg== X-Received: by 2002:a17:902:b81:: with SMTP id 1-v6mr10877738plr.164.1532806881530; Sat, 28 Jul 2018 12:41:21 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:38 +0530 Message-Id: <1532800907-29115-24-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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]); Sat, 28 Jul 2018 19:41:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 28 Jul 2018 19:41:22 +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.111 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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.48 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 23/32] 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.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.40]); Sat, 28 Jul 2018 19:41:35 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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 | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 8d28387..6b00559 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -221,30 +221,31 @@ virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t= src_pid, ssize_t nbytes; int fd; int n; - virNetlinkHandlePtr nlhandle =3D NULL; + VIR_AUTOPTR(virNetlinkHandle) nlhandle =3D NULL; + virNetlinkHandlePtr temp =3D NULL; struct pollfd fds[1]; struct nlmsghdr *nlmsg =3D nlmsg_hdr(nl_msg); =20 if (protocol >=3D MAX_LINKS) { virReportSystemError(EINVAL, _("invalid protocol argument: %d"), protocol); - goto error; + return NULL; } =20 if (!(nlhandle =3D virNetlinkCreateSocket(protocol))) - goto error; + return NULL; =20 fd =3D nl_socket_get_fd(nlhandle); if (fd < 0) { virReportSystemError(errno, "%s", _("cannot get netlink socket fd")); - goto error; + return NULL; } =20 if (groups && nl_socket_add_membership(nlhandle, groups) < 0) { virReportSystemError(errno, "%s", _("cannot add netlink membership")); - goto error; + return NULL; } =20 nlmsg_set_dst(nl_msg, &nladdr); @@ -255,7 +256,7 @@ virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t s= rc_pid, if (nbytes < 0) { virReportSystemError(errno, "%s", _("cannot send to netlink socket")); - goto error; + return NULL; } =20 memset(fds, 0, sizeof(fds)); @@ -273,11 +274,9 @@ virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t = src_pid, _("no valid netlink response was received= ")); } =20 - return nlhandle; + VIR_STEAL_PTR(temp, nlhandle); =20 - error: - virNetlinkFree(nlhandle); - return NULL; + return temp; } =20 /** @@ -307,7 +306,7 @@ int virNetlinkCommand(struct nl_msg *nl_msg, .nl_groups =3D 0, }; struct pollfd fds[1]; - virNetlinkHandlePtr nlhandle =3D NULL; + VIR_AUTOPTR(virNetlinkHandle) nlhandle =3D NULL; int len =3D 0; =20 memset(fds, 0, sizeof(fds)); @@ -335,7 +334,6 @@ int virNetlinkCommand(struct nl_msg *nl_msg, *respbuflen =3D 0; } =20 - virNetlinkFree(nlhandle); return ret; } =20 @@ -346,10 +344,8 @@ 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 *resp =3D NULL; struct nlmsghdr *msg =3D NULL; =20 struct sockaddr_nl nladdr =3D { @@ -357,13 +353,14 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, .nl_pid =3D dst_pid, .nl_groups =3D 0, }; - virNetlinkHandlePtr 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; 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= )) { @@ -372,20 +369,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; } - VIR_FREE(resp); } =20 - ret =3D 0; - - cleanup: - VIR_FREE(resp); - virNetlinkFree(nlhandle); - return ret; + return 0; } =20 /** @@ -527,7 +518,7 @@ int virNetlinkDelLink(const char *ifname, virNetlinkDelLinkFallback fallback) { 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 }; unsigned int recvbuflen; @@ -582,7 +573,6 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLink= Fallback fallback) rc =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -771,7 +761,7 @@ virNetlinkEventCallback(int watch, void *opaque) { virNetlinkEventSrvPrivatePtr srv =3D opaque; - struct nlmsghdr *msg; + VIR_AUTOFREE(struct nlmsghdr *) msg =3D NULL; struct sockaddr_nl peer; struct ucred *creds =3D NULL; size_t i; @@ -806,7 +796,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