From nobody Tue May 13 18:30:09 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 1530481505225538.554179392944; Sun, 1 Jul 2018 14:45:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D95B33086249; Sun, 1 Jul 2018 21:45:03 +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 920E4308BDBB; Sun, 1 Jul 2018 21:45:03 +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 1A7C9264FB; Sun, 1 Jul 2018 21:45:03 +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 w61Lj1u4009323 for ; Sun, 1 Jul 2018 17:45:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 31DAD17CDB; Sun, 1 Jul 2018 21:45:01 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 293D017D0F for ; Sun, 1 Jul 2018 21:44:58 +0000 (UTC) Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) (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 8F887308212F for ; Sun, 1 Jul 2018 21:44:47 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id j17-v6so6530726pfn.5 for ; Sun, 01 Jul 2018 14:44:47 -0700 (PDT) Received: from centos.localdomain ([157.37.164.55]) by smtp.gmail.com with ESMTPSA id v68-v6sm15006933pfv.143.2018.07.01.14.44.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Jul 2018 14:44:46 -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=lFsX1T9niIpbAIyB8ZfvwfZ97t74pSrHPdkySwSBHqk=; b=dSwhr+PnedFZzetE56nbsdyiphHXlKx14XKdoroQ0iQDFBHlLxY/32hCGHAfonmvuF LGQpSUy0M6G64W7V3lnPZN0F9wLZxICzx2Hr4TKd0EhYxGiWGl6k/njQJBA7LE9o2vsr t0uBrYE3o7Sr24phtxHK7uw/iMJ0zDYq9ubUG23K3zQDAlQhCeX579/Cww+sz/t9vFaY 7O8hzvbH3/H4yQuWurKZPp+O2I3/XKHsgqx1i2YsD1OQljLEY0SVTd3tnF/YoeCOuAVI 18sOhssITQD2MkzmudXyWbxMO03D5exAtPf+O1FnprsNffDYos5ja7zaCrjwspfHzikF u9eg== 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=lFsX1T9niIpbAIyB8ZfvwfZ97t74pSrHPdkySwSBHqk=; b=tgWoS2YuY5ZDxdFEVeQoP9208uPp9Mq7gsNRmXMd+PMtiQaVBjwiiaS1tyFEPbXTZ5 vJUxE7ObY7RRzt8ekuYGbikctGXCzaVWcajBmPWamx+Dlp3fn1OOfhz82gxdLfXLUwOo djctU/i5yOrJ5cuSgc+B7X1HDq5sRnCDD/9R47jC+hYHCiVUvp5SGPPKUto2k7LZG6pm EWWSweNRrpPe5gg7cS4GnxZGbm5uS/vZvhNZry+NmASo0SxKMn5EAA02Qh3j2UQLk/2O 5upsf8IqyM6sns/mZdG+2LD7+BGkYqFoQuyuanODeVRpIMNWgh/TO9xrtqswA0BOYQAm 9HsA== X-Gm-Message-State: APt69E1B+uIyWEDT5VJxP0hWz39zt49gRmz32csWRKKazM0VrLH7FnvP xvc/djZ07SkpSVJUdxYK7/AyJIgH X-Google-Smtp-Source: AAOMgpeUxtyherRoc8DJvWhHs5CAOSDy58x7ytRjH4fuN/JpVlIDEU6lSw0GWZF6quhd/JVJTRUm+A== X-Received: by 2002:a65:4acd:: with SMTP id c13-v6mr14796217pgu.436.1530481486863; Sun, 01 Jul 2018 14:44:46 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 30 Jun 2018 14:30:24 +0530 Message-Id: <1530349239-22049-21-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1530349239-22049-1-git-send-email-skrtbhtngr@gmail.com> References: <1530349239-22049-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.42]); Sun, 01 Jul 2018 21:44:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sun, 01 Jul 2018 21:44:47 +0000 (UTC) for IP:'209.85.192.193' DOMAIN:'mail-pf0-f193.google.com' HELO:'mail-pf0-f193.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.785 * (DATE_IN_PAST_24_48, 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.192.193 mail-pf0-f193.google.com 209.85.192.193 mail-pf0-f193.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 20/35] 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sun, 01 Jul 2018 21:45:04 +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_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 Reviewed-by: Erik Skultety --- 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