From nobody Mon Feb 9 15:09:59 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 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