From nobody Tue May 13 22:23:15 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 1528400133881656.3936967118748; Thu, 7 Jun 2018 12:35:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AFCB74E4C2; Thu, 7 Jun 2018 19:35:32 +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 7F8E52B3AF; Thu, 7 Jun 2018 19:35:32 +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 2CB7B1800FD9; Thu, 7 Jun 2018 19:35:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w57JZTa2019007 for ; Thu, 7 Jun 2018 15:35:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id BD32D5D9CA; Thu, 7 Jun 2018 19:35:29 +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 B687B5D9C9 for ; Thu, 7 Jun 2018 19:35:26 +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 5FA4030820DC for ; Thu, 7 Jun 2018 19:35:15 +0000 (UTC) Received: by mail-pl0-f47.google.com with SMTP id a7-v6so4265209plp.3 for ; Thu, 07 Jun 2018 12:35:15 -0700 (PDT) Received: from centos.localdomain ([49.32.106.159]) by smtp.gmail.com with ESMTPSA id d23-v6sm86686407pfn.3.2018.06.07.12.35.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 12:35:14 -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=pUQLnb1h10lRHFDW1PQWyXbI0Qo7ETfX8oOc0QbSXMM=; b=V9iuhY+s6vXkSbZ3vr3HvuexVEqaByev1BmF9HYmXI3gXHS3/5VL5IcrrVAGebsd3A K9DtvQUECjdawDMpS9GGwgjPU2WpCPK5R1p3GpiLBvMGXmhnwBAh4bG9yI/Br0zeWvwY ciWxvYLV76JGYVweD9hxu/uzZ93/21dLsyO71Go5AEm3VZxWmn7AD5xXwjstkkX+qFDc xLoLRZUAYluDOEf2+lMOKsFn76OT79Bo/T5L8dVOjbdqnkB66DSiAe8YMXIhKygx/l/7 G6CzkdcxLy8e/39hM6MBzB0Q0+7wNXY5gLxU05fSuwYwnb/I4nEX9lICPBSpqMz3ZTng TyYg== 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=pUQLnb1h10lRHFDW1PQWyXbI0Qo7ETfX8oOc0QbSXMM=; b=S6+hR+hlFu9wSQlRwbqL3rGzWiUniRIJBWUxnqw0bH9C3vRP0rJ5MgN1tv4EutqaU4 rsjbOmr+3rELKlhUWi20g+PzPWp8+xqci211mSjujQ5e1v0oqLuMlLq0nko3FW/Kub3K 402lYhxrfOh8S6zbQrz9WBcU9nNUhltMso2sLzEJq5F2Zlb1xo1PaSEksbZQ2jm5GxUC C08eAhdhWF8oHnNIcXghoXzpZlVOJE5jGehRQ/MeCJiBd4MWHMw2nuXKUL69gaEO/0sE Z21HXbYIjxAoub8e+8hTLi1eGofcrR+TwSnYJNBvm1cCqrujF7tb6Rnqnq05td9/JXyq 7F4g== X-Gm-Message-State: APt69E1M7BMja3hQK2omCWZLcYM7oW0K5yTOPEFwluhPhIGSCniMs4bR BEEKwb1hKSkQqGcG4lKq4VjLLABd X-Google-Smtp-Source: ADUXVKKfPkYa3+hFLIgVgbxGfKO2mnex1T0VhUykKwcuzCpWQCsiPxCowNiJO6iT0O+qF7GcENEPNg== X-Received: by 2002:a17:902:4b:: with SMTP id 69-v6mr3402811pla.178.1528400114599; Thu, 07 Jun 2018 12:35:14 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 8 Jun 2018 01:04:32 +0530 Message-Id: <1528400083-6788-11-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528400083-6788-1-git-send-email-skrtbhtngr@gmail.com> References: <1528400083-6788-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, 07 Jun 2018 19:35:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 07 Jun 2018 19:35:15 +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.511 (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 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.47 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 10/21] util: authconfig: 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 07 Jun 2018 19:35:33 +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 the GCC's __attribute__((cleanup)) handled by VIR_AUTOFREE macro, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. --- src/util/virauthconfig.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index 3487cc2..9977e71 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -105,10 +105,9 @@ int virAuthConfigLookup(virAuthConfigPtr auth, const char *credname, const char **value) { - char *authgroup =3D NULL; - char *credgroup =3D NULL; + VIR_AUTOFREE(char *) authgroup =3D NULL; + VIR_AUTOFREE(char *) credgroup =3D NULL; const char *authcred; - int ret =3D -1; =20 *value =3D NULL; =20 @@ -118,47 +117,38 @@ int virAuthConfigLookup(virAuthConfigPtr auth, hostname =3D "localhost"; =20 if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0) - goto cleanup; + return -1; =20 if (!virKeyFileHasGroup(auth->keyfile, authgroup)) { VIR_FREE(authgroup); if (virAsprintf(&authgroup, "auth-%s-%s", service, "default") < 0) - goto cleanup; + return -1; } =20 - if (!virKeyFileHasGroup(auth->keyfile, authgroup)) { - ret =3D 0; - goto cleanup; - } + if (!virKeyFileHasGroup(auth->keyfile, authgroup)) + return 0; =20 if (!(authcred =3D virKeyFileGetValueString(auth->keyfile, authgroup, = "credentials"))) { virReportError(VIR_ERR_CONF_SYNTAX, _("Missing item 'credentials' in group '%s' in '%s'= "), authgroup, auth->path); - goto cleanup; + return -1; } =20 if (virAsprintf(&credgroup, "credentials-%s", authcred) < 0) - goto cleanup; + return -1; =20 if (!virKeyFileHasGroup(auth->keyfile, credgroup)) { virReportError(VIR_ERR_CONF_SYNTAX, _("Missing group 'credentials-%s' referenced from g= roup '%s' in '%s'"), authcred, authgroup, auth->path); - goto cleanup; + return -1; } =20 - if (!virKeyFileHasValue(auth->keyfile, credgroup, credname)) { - ret =3D 0; - goto cleanup; - } + if (!virKeyFileHasValue(auth->keyfile, credgroup, credname)) + return 0; =20 *value =3D virKeyFileGetValueString(auth->keyfile, credgroup, credname= ); =20 - ret =3D 0; - - cleanup: - VIR_FREE(authgroup); - VIR_FREE(credgroup); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list