From nobody Wed Jul 16 12:52:25 2025 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 1533817990238768.0230782649958; Thu, 9 Aug 2018 05:33:10 -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 1E0EA81E04; Thu, 9 Aug 2018 12:33:08 +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 E1B2D1001940; Thu, 9 Aug 2018 12:33: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 95C8418037F0; Thu, 9 Aug 2018 12:33:07 +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 w79CWv51000414 for ; Thu, 9 Aug 2018 08:32:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id F2C8660C80; Thu, 9 Aug 2018 12:32:56 +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 DFF0A60C11 for ; Thu, 9 Aug 2018 12:32:54 +0000 (UTC) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 2BA28307B974 for ; Thu, 9 Aug 2018 12:32:53 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id i26-v6so2776517pfo.12 for ; Thu, 09 Aug 2018 05:32:53 -0700 (PDT) Received: from centos.localdomain ([49.33.163.55]) by smtp.gmail.com with ESMTPSA id j15-v6sm8649810pfn.52.2018.08.09.05.32.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 05:32:51 -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=c7yGoGYvSNVtG4dYDZFfYgVTfk4ktPqvLfXNKwZuYHs=; b=brQRDcoDKn7k1knXuXNHNjhxy5RQTucKVtcP7LKqwYlnk5FwzkuCMwPrmLQjekk3mu fc9GTeWTye2PY0fr8EczxU7wFieFhwJheWrV2mufjfVNMH9AGIhnYFiKx5GBeTGVP1yY 4BzuCRnlChY1Yk/bEsuLTp1G/1Yh/untzsNQIFVg3Nq7n/1jWcI1JA6K8ml67tdzB/nq 4bcWcYZVmUZPpHwBfRbKL5IY7mp73mtcZrqEfukMX1a01trdhaxEoAd7u6995tJ/if3p HxoAgmqM9Mp2JixK2UzltQHGMB5x4nlKyJC/v5GiysNCnzc9gQV6xcQ+Li/CAP37jeSY zu5g== 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=c7yGoGYvSNVtG4dYDZFfYgVTfk4ktPqvLfXNKwZuYHs=; b=J3kSYdXLIRICH3CSY+MMsA1HkQDT6oO5HhkOfGKBSVIt9nzCAq9qZrYPZiUW8awZBJ 7AHtGYHbw1dDPJ+t344DzMvwyu+YlOca6g4nUcrZITX9U5xBIoJR3E4o0MwG+oTyiqEj RhkJEjmOZFvoo53i9iBZLl8omKIdiVeoS4OfBUpzqlbdWUFoHke7QRUMk7wSjDnLsmkC RMoqcWH1yYxA3AkZmO9PfBtc9NM1CBgRDBMSHNJEWqbUSX3Pd+OEXhOWCj3QRGot19bC cULZfYqZKxG+H4OW7ribwyiWHVBEetgDc+/RgpqThZfIQHxg6KT/g51dqUuZJpV+ZvGg hN9w== X-Gm-Message-State: AOUpUlFuVA70809wfdzYL62dyV+SYO856TB9RVJg5Ui1retsHqca7J8c A4Dh+BRSmHR/y+s2qb2LdazBbURt X-Google-Smtp-Source: AA+uWPzm7JOFEoYTyJd8Q95Biqd2kZ9AEMc8tQfrdjiFdpK2AILKdp40sCN4UibglmRyb6hhDyHkTA== X-Received: by 2002:a63:6441:: with SMTP id y62-v6mr2001321pgb.240.1533817971847; Thu, 09 Aug 2018 05:32:51 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 09:42:11 +0530 Message-Id: <1533787939-28634-4-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533787939-28634-1-git-send-email-skrtbhtngr@gmail.com> References: <1533787939-28634-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]); Thu, 09 Aug 2018 12:32:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 09 Aug 2018 12:32:53 +0000 (UTC) for IP:'209.85.210.169' DOMAIN:'mail-pf1-f169.google.com' HELO:'mail-pf1-f169.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.993 (DATE_IN_PAST_06_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.210.169 mail-pf1-f169.google.com 209.85.210.169 mail-pf1-f169.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 v3 03/11] 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 09 Aug 2018 12:33:08 +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/virnetlink.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index ecf62c9..fcdc09d 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -342,10 +342,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,9 +355,11 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, =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= )) { @@ -368,19 +368,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); - return ret; + return 0; } =20 /** @@ -408,7 +403,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, @@ -416,6 +410,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; @@ -483,12 +480,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: @@ -522,11 +519,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); @@ -577,7 +574,6 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLink= Fallback fallback) rc =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -610,13 +606,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) { @@ -654,13 +652,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: @@ -766,12 +763,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); @@ -801,7 +798,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