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 1528400151239747.1234022318897; Thu, 7 Jun 2018 12:35:51 -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 1FCD4356DF; Thu, 7 Jun 2018 19:35:50 +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 D73672016A81; Thu, 7 Jun 2018 19:35:49 +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 8BBBB4CA84; Thu, 7 Jun 2018 19:35:49 +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 w57JZYNp019042 for ; Thu, 7 Jun 2018 15:35:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 86CEB2B4C7; Thu, 7 Jun 2018 19:35:34 +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 80E552B4BB for ; Thu, 7 Jun 2018 19:35:31 +0000 (UTC) Received: from mail-pl0-f45.google.com (mail-pl0-f45.google.com [209.85.160.45]) (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 F0B3B30820DF for ; Thu, 7 Jun 2018 19:35:20 +0000 (UTC) Received: by mail-pl0-f45.google.com with SMTP id g20-v6so6770672plq.1 for ; Thu, 07 Jun 2018 12:35:20 -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.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 12:35:19 -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=4YCRiQLcPsKCmsafgiwcrZ5Bk85CguKq6P1JrNSDOQA=; b=Hj+D/uVfA3MBpTFAqMQ/cLwkckh3AXq8eSjDx2TVLHhdBTgiHvs6Ms4ePYt61HBUHM NI5IYLROphnmH1rL5uiBQJDSNCwzV8YYb1TXTldBiIav+JAY4/Iep4hVjL/J0b76iv21 bGd5gLXQD8CT2obHlgr1at8alIwWskolVjsRvwF3AiztSfbDyw6q5kFHCDsGdUSzR4NC ukGKZb2uaUOoIYSS8N1gMPxRDY3cuR+SVcnXy0nq+zTQPjDGc8/p/MvZeE6cMzjQ7l0b IiCallMrsncn0mk2rcIlxTXjhFtImw5qbz9KlUxUVIWO/rEcQfY/CqbcrckAkREMeayL 5eEQ== 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=4YCRiQLcPsKCmsafgiwcrZ5Bk85CguKq6P1JrNSDOQA=; b=jS6cjohLsFFgF9gsUR7LbmuUKvU+uMNVQ7o6pkODh3+TADhvT0QksZL84CQ9eHBWBt d3jFIbzwM+gEulB217/igAUdsFd/a00OXcL7KKyN56zb19SFH8z8uBPtXiOdxLa8/J/R 63ESDnqgW1SL6Xexu+GcbTN8ZwiFuqmnvd1djoTm8a4JEDawvtJgHm1Nu8SkCe2/3hdR XSUPSVmwxpseRD7EufZsHoX0ITRdgmlT23Q9h3X6MWSgRDCl8jymLP/u+/jtpFxm6ZAX fn7hGQu8JMHKMP5GTGqcp2ohguXSVuJoiIr0YiH2LI70mBBggKDh5YhRUVImxfAVs5g7 t7aw== X-Gm-Message-State: APt69E3aaVO78W1AVsw/3HZwmiTEfBkuP8L8hF0DFya9p2upW/htc4kR dK8RjMhlqSmGqmtNYDMkUDEO4ig1 X-Google-Smtp-Source: ADUXVKJQVIgjUN3iMrbonbYXXWkyE/P7k4npbemkzKxcRj3fn1R68pO4bBptdZUsUDRQbZzxoCmHGQ== X-Received: by 2002:a17:902:740a:: with SMTP id g10-v6mr3414549pll.246.1528400120021; Thu, 07 Jun 2018 12:35:20 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 8 Jun 2018 01:04:34 +0530 Message-Id: <1528400083-6788-13-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:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 07 Jun 2018 19:35:21 +0000 (UTC) for IP:'209.85.160.45' DOMAIN:'mail-pl0-f45.google.com' HELO:'mail-pl0-f45.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.160.45 mail-pl0-f45.google.com 209.85.160.45 mail-pl0-f45.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 12/21] util: auth: 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.30]); Thu, 07 Jun 2018 19:35:50 +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/virauth.c | 45 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/src/util/virauth.c b/src/util/virauth.c index c6a2ce7..d3a5cc7 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -41,10 +41,9 @@ int virAuthGetConfigFilePathURI(virURIPtr uri, char **path) { - int ret =3D -1; size_t i; const char *authenv =3D virGetEnvBlockSUID("LIBVIRT_AUTH_FILE"); - char *userdir =3D NULL; + VIR_AUTOFREE(char *) userdir =3D NULL; =20 *path =3D NULL; =20 @@ -53,7 +52,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri, if (authenv) { VIR_DEBUG("Using path from env '%s'", authenv); if (VIR_STRDUP(*path, authenv) < 0) - goto cleanup; + return -1; return 0; } =20 @@ -63,17 +62,17 @@ virAuthGetConfigFilePathURI(virURIPtr uri, uri->params[i].value) { VIR_DEBUG("Using path from URI '%s'", uri->params[i].value= ); if (VIR_STRDUP(*path, uri->params[i].value) < 0) - goto cleanup; + return -1; return 0; } } } =20 if (!(userdir =3D virGetUserConfigDirectory())) - goto cleanup; + return -1; =20 if (virAsprintf(path, "%s/auth.conf", userdir) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Checking for readability of '%s'", *path); if (access(*path, R_OK) =3D=3D 0) @@ -82,7 +81,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri, VIR_FREE(*path); =20 if (VIR_STRDUP(*path, SYSCONFDIR "/libvirt/auth.conf") < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Checking for readability of '%s'", *path); if (access(*path, R_OK) =3D=3D 0) @@ -91,13 +90,9 @@ virAuthGetConfigFilePathURI(virURIPtr uri, VIR_FREE(*path); =20 done: - ret =3D 0; - VIR_DEBUG("Using auth file '%s'", NULLSTR(*path)); - cleanup: - VIR_FREE(userdir); =20 - return ret; + return 0; } =20 =20 @@ -155,7 +150,7 @@ virAuthGetUsernamePath(const char *path, { unsigned int ncred; virConnectCredential cred; - char *prompt; + VIR_AUTOFREE(char *) prompt =3D NULL; char *ret =3D NULL; =20 if (virAuthGetCredential(servicename, hostname, "username", path, &ret= ) < 0) @@ -192,8 +187,6 @@ virAuthGetUsernamePath(const char *path, break; } =20 - VIR_FREE(prompt); - return cred.result; } =20 @@ -205,18 +198,13 @@ virAuthGetUsername(virConnectPtr conn, const char *defaultUsername, const char *hostname) { - char *ret; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAuthGetConfigFilePath(conn, &path) < 0) return NULL; =20 - ret =3D virAuthGetUsernamePath(path, auth, servicename, + return virAuthGetUsernamePath(path, auth, servicename, defaultUsername, hostname); - - VIR_FREE(path); - - return ret; } =20 =20 @@ -229,7 +217,7 @@ virAuthGetPasswordPath(const char *path, { unsigned int ncred; virConnectCredential cred; - char *prompt; + VIR_AUTOFREE(char *) prompt =3D NULL; char *ret =3D NULL; =20 if (virAuthGetCredential(servicename, hostname, "password", path, &ret= ) < 0) @@ -263,8 +251,6 @@ virAuthGetPasswordPath(const char *path, break; } =20 - VIR_FREE(prompt); - return cred.result; } =20 @@ -276,15 +262,10 @@ virAuthGetPassword(virConnectPtr conn, const char *username, const char *hostname) { - char *ret; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAuthGetConfigFilePath(conn, &path) < 0) return NULL; =20 - ret =3D virAuthGetPasswordPath(path, auth, servicename, username, host= name); - - VIR_FREE(path); - - return ret; + return virAuthGetPasswordPath(path, auth, servicename, username, hostn= ame); } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list