From nobody Wed May 14 16:51:19 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1520346482896362.80802794226474; Tue, 6 Mar 2018 06:28:02 -0800 (PST) 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 42B18C0587D2; Tue, 6 Mar 2018 14:28:01 +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 18FC7600C9; Tue, 6 Mar 2018 14:28:01 +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 C4D4C4A470; Tue, 6 Mar 2018 14:28:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w26ERwF4023048 for ; Tue, 6 Mar 2018 09:27:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id C08122024CAB; Tue, 6 Mar 2018 14:27:58 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AB1A2024CAD; Tue, 6 Mar 2018 14:27:58 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 6 Mar 2018 15:27:10 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 1/6] util: storage: Simplify error handling in virStorageAuthDefParseXML 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.32]); Tue, 06 Mar 2018 14:28:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Unify the cleanup and error paths and simplify the code flow by removing some unnecessary variables. Signed-off-by: Peter Krempa --- src/util/virstoragefile.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index d1972d6d1d..3d17911297 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1813,20 +1813,18 @@ static virStorageAuthDefPtr virStorageAuthDefParseXML(xmlXPathContextPtr ctxt) { virStorageAuthDefPtr authdef =3D NULL; + virStorageAuthDefPtr ret =3D NULL; xmlNodePtr secretnode =3D NULL; - char *username =3D NULL; char *authtype =3D NULL; if (VIR_ALLOC(authdef) < 0) return NULL; - if (!(username =3D virXPathString("string(./@username)", ctxt))) { + if (!(authdef->username =3D virXPathString("string(./@username)", ctxt= ))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing username for auth")); - goto error; + goto cleanup; } - authdef->username =3D username; - username =3D NULL; authdef->authType =3D VIR_STORAGE_AUTH_TYPE_NONE; authtype =3D virXPathString("string(./@type)", ctxt); @@ -1837,15 +1835,14 @@ virStorageAuthDefParseXML(xmlXPathContextPtr ctxt) if ((authdef->authType =3D virStorageAuthTypeFromString(authtype))= < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown auth type '%s'"), authtype); - goto error; + goto cleanup; } - VIR_FREE(authtype); } if (!(secretnode =3D virXPathNode("./secret ", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing element in auth")); - goto error; + goto cleanup; } /* Used by the domain disk xml parsing in order to ensure the @@ -1858,15 +1855,15 @@ virStorageAuthDefParseXML(xmlXPathContextPtr ctxt) authdef->secrettype =3D virXMLPropString(secretnode, "type"); if (virSecretLookupParseSecret(secretnode, &authdef->seclookupdef) < 0) - goto error; + goto cleanup; - return authdef; + VIR_STEAL_PTR(ret, authdef); - error: + cleanup: VIR_FREE(authtype); - VIR_FREE(username); virStorageAuthDefFree(authdef); - return NULL; + + return ret; } --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list