From nobody Sun Feb 8 05:54:49 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 1532806883352511.6693539863618; Sat, 28 Jul 2018 12:41:23 -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 91BA6308213B; Sat, 28 Jul 2018 19:41:21 +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 543236016F; Sat, 28 Jul 2018 19:41: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 00D5F180053A; Sat, 28 Jul 2018 19:41:20 +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 w6SJesfK020448 for ; Sat, 28 Jul 2018 15:40:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id B899D600C8; Sat, 28 Jul 2018 19:40:54 +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 B0BBC600C5 for ; Sat, 28 Jul 2018 19:40:54 +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 B6AE085A04 for ; Sat, 28 Jul 2018 19:40:53 +0000 (UTC) Received: by mail-pl0-f53.google.com with SMTP id 31-v6so3738760plc.4 for ; Sat, 28 Jul 2018 12:40:53 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40: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=6GC/yBHaInmLT67+NyBMzJ3/zne6Wtq/+Etry80lCgA=; b=BUBI7BcGu+jE5cfqGE2Z6aUkkA9wqlhWXLRfAKDtTpFEfKPcSoovFgQw3nHkpTvqZz DimQCN1PwGaz4gJkqBfuS5ueR54aHLEugYCNkWfGuAyXeFqR5YFX/srkeNsVk6OYT/xf LfEMZdG4Ic4y82OlOLBsjSA+OzG+FOKmW5pXxrdFYHAxKGqeOK/fWfVjcm5pgE05kyIv 4TxiOpIJsdGZW5k4Vr8cCVwzTS56oNvzikv8pL62JFc/ow3plTQmgMHA/oZeIfAJ6OWA e09WtuB3Xef+0MA1sAo6Yk3WqF3tIgeh2rN21AT8RuS8UVENUsl7vK/r73W7hsWeamAn gHew== 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=6GC/yBHaInmLT67+NyBMzJ3/zne6Wtq/+Etry80lCgA=; b=f7CaEalDuFwDcSjzuAWp+iYbPE1pgrWOh6YHeS4F6h0duoTL/MXBIzrSuWPSwg9Cqc B5MWaqsDAtTQVEnUrFtAqbd7Y6MO4f/giykdUfigX7Mox3z5hLomlRL6x8ZkU+1/9Zce SqIiTNiieFvJyMGEkuwcWVyKPvF5lZ3kLCHx5FwT44qB/lh/x/5DHuKJch7GGOEogGy1 fhQJnt3136dSnbAJUaPiKdvWS+6X/QEzT0pTgSek+9MU+R2RCg3G34IaiISrAD9OqU56 1Gef4LUIoFZzuXiLrDK8ls+rjqD9L2NZprQsWpNb1t9XYK6OR5LTkBCqYehzygYYI/Gs Pv6Q== X-Gm-Message-State: AOUpUlEKbajfxVJq/pNdDTuetK8RJqXiHLnU0Zm5b9lFZK9C1E7bPaHP 2S/Mbg5WQLtZdJw/bYk5TPP3/NxL X-Google-Smtp-Source: AAOMgpd6zwR9YCm+8+L4rzAT9IsgzIoi2cpQykbLrpRb3XV1tLiaBhUoI0dptzTADcaUX4Io7c9Xag== X-Received: by 2002:a17:902:e3:: with SMTP id a90-v6mr10897384pla.227.1532806853016; Sat, 28 Jul 2018 12:40:53 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:25 +0530 Message-Id: <1532800907-29115-11-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.26]); Sat, 28 Jul 2018 19:40:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 28 Jul 2018 19:40:53 +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.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, 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.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 10/32] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sat, 28 Jul 2018 19:41:22 +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 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..1b195cd 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; + VIR_AUTOPTR(virBuffer) buf =3D NULL; size_t i; - int ret =3D -1; + + 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