From nobody Mon Feb 9 02:12:20 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 1531504577816939.9749534858925; Fri, 13 Jul 2018 10:56:17 -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 48E6C3E2D1; Fri, 13 Jul 2018 17:56:16 +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 0AA3819489; Fri, 13 Jul 2018 17:56:16 +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 9ABC63FCC1; Fri, 13 Jul 2018 17:56:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHu3Eh008489 for ; Fri, 13 Jul 2018 13:56:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id BAD9E3001A55; Fri, 13 Jul 2018 17:56:03 +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 B45B330012C2 for ; Fri, 13 Jul 2018 17:56:01 +0000 (UTC) Received: from mail-pl0-f49.google.com (mail-pl0-f49.google.com [209.85.160.49]) (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 C67A7308212A for ; Fri, 13 Jul 2018 17:55:50 +0000 (UTC) Received: by mail-pl0-f49.google.com with SMTP id 30-v6so12500845pld.13 for ; Fri, 13 Jul 2018 10:55:50 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:49 -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=LEDiP2AJsHYedYtV7+w0+drJZu9pqfEmlvox/BaUu7s=; b=Zg288JHDNHGZJ0l+oYOBquMsUyLDAf0j9SafzhtFaQEbr0UdUQpNQe3ZER0dSggPGS s7uEariZSfLH6WEbaMcCBhIRgK4vd9dFk84y/NyKWaiBg1x3WLt6ztxjmMhrNk3dz/o+ QGleTmAC5duXc4ZdLfaVi+hQoxxrOGIvFVWY1dWhuMvYsO+uBAqawGmoM7CEJm3Odvtb Z2vAGBhrPm/i2xm6lp6tXTz8dyzMK4SdV/GEjYBz+THzNSFoxYX+wf00fWOiSPicNepe yQSORvz1XqdEZ3RUWFHjVrctM+NSP9DtWLWXytFOlcsPHwIp8PQJn/wanHfxlBoGIGVY Sq+w== 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=LEDiP2AJsHYedYtV7+w0+drJZu9pqfEmlvox/BaUu7s=; b=tpVvVXcTMV5ddp5fePZ/5CXt9oWu4nykyQBc/GBs73cxeNYPD2aDx34qa7lcKgGIWr 1pMYq+4fBkTqtDnBe1Q0r0JoXDFU+HMfvlI8u0zZQy43V7G4DpDZe/2NXjBOHnzoGpls 69Ns8xprtTiBGYwPnjkV660Mtjt8HyvOleaiivv8VEBx/HH2Lq+lmedm/kFDP0O1D1CI 1GPr+QucFkD7GW8FRGt4d+aKp3V3uVPs6FXTihxnuhIy0+U4WTevtW+Gzqx2En1VUsnw L08kYRnN6w3N02V7kh79CmY+F1FGZA3o8Q8V0vUTxWJVAebFx+igPjCom29pUG5IGB7Y 44lg== X-Gm-Message-State: AOUpUlH/FhdWqqzG7vR2u7BVppyBm3yRzS9ds3R8y1c7UBthCktUc+X0 m0OtpIDn8rqU1IkdtkoQq4VXP+La X-Google-Smtp-Source: AAOMgpf2ZVret1nIbA439Xktzc5+ekZ8yYIqLfYrJxnQRJn+mTTzbrhib1map8YSH7Qv6VvKVKOebw== X-Received: by 2002:a17:902:bc8c:: with SMTP id bb12-v6mr7429489plb.84.1531504550075; Fri, 13 Jul 2018 10:55:50 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:52 +0530 Message-Id: <1531504509-7930-15-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1531504509-7930-1-git-send-email-skrtbhtngr@gmail.com> References: <1531504509-7930-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]); Fri, 13 Jul 2018 17:55:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 13 Jul 2018 17:55:50 +0000 (UTC) for IP:'209.85.160.49' DOMAIN:'mail-pl0-f49.google.com' HELO:'mail-pl0-f49.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.49 mail-pl0-f49.google.com 209.85.160.49 mail-pl0-f49.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 14/31] 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.30]); Fri, 13 Jul 2018 17:56:17 +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/virauthconfig.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index 3487cc2..4acdf1d 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