From nobody Sat Feb 7 05:35:24 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 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