From nobody Wed May 14 17:13: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 1520346486522835.2382196979532; Tue, 6 Mar 2018 06:28:06 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E2E47ECFF; Tue, 6 Mar 2018 14:28:04 +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 655D25C88A; Tue, 6 Mar 2018 14:28:04 +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 2C0304A474; Tue, 6 Mar 2018 14:28:04 +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 w26ES1qA023071 for ; Tue, 6 Mar 2018 09:28:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id E54F7200AE93; Tue, 6 Mar 2018 14:28:00 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F9B62026DFD; Tue, 6 Mar 2018 14:28:00 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 6 Mar 2018 15:27:13 +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 4/6] util: storageencryption: Refactor cleanup section in virStorageEncryptionParseXML 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 06 Mar 2018 14:28:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The function used the 'cleanup' label only in error cases. This patch makes the code pass the cleanup label in every case and removes few unnecessary VIR_FREEs. Signed-off-by: Peter Krempa --- src/util/virstorageencryption.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/util/virstorageencryption.c b/src/util/virstorageencryptio= n.c index 116a2358ae..f3de5ff7a7 100644 --- a/src/util/virstorageencryption.c +++ b/src/util/virstorageencryption.c @@ -246,13 +246,14 @@ static virStorageEncryptionPtr virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) { xmlNodePtr *nodes =3D NULL; - virStorageEncryptionPtr ret; + virStorageEncryptionPtr encdef =3D NULL; + virStorageEncryptionPtr ret =3D NULL; char *format_str =3D NULL; int n; size_t i; - if (VIR_ALLOC(ret) < 0) - return NULL; + if (VIR_ALLOC(encdef) < 0) + goto cleanup; if (!(format_str =3D virXPathString("string(./@format)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -260,60 +261,57 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) goto cleanup; } - if ((ret->format =3D + if ((encdef->format =3D virStorageEncryptionFormatTypeFromString(format_str)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown volume encryption format type %s"), format_str); goto cleanup; } - VIR_FREE(format_str); if ((n =3D virXPathNodeSet("./secret", ctxt, &nodes)) < 0) goto cleanup; if (n > 0) { - if (VIR_ALLOC_N(ret->secrets, n) < 0) + if (VIR_ALLOC_N(encdef->secrets, n) < 0) goto cleanup; - ret->nsecrets =3D n; + encdef->nsecrets =3D n; for (i =3D 0; i < n; i++) { - if (!(ret->secrets[i] =3D + if (!(encdef->secrets[i] =3D virStorageEncryptionSecretParse(ctxt, nodes[i]))) goto cleanup; } - VIR_FREE(nodes); } - if (ret->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) { + if (encdef->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) { xmlNodePtr tmpnode; if ((tmpnode =3D virXPathNode("./cipher[1]", ctxt))) { - if (virStorageEncryptionInfoParseCipher(tmpnode, &ret->encinfo= ) < 0) + if (virStorageEncryptionInfoParseCipher(tmpnode, &encdef->enci= nfo) < 0) goto cleanup; } if ((tmpnode =3D virXPathNode("./ivgen[1]", ctxt))) { /* If no cipher node, then fail */ - if (!ret->encinfo.cipher_name) { + if (!encdef->encinfo.cipher_name) { virReportError(VIR_ERR_XML_ERROR, "%s", _("ivgen element found, but cipher is miss= ing")); goto cleanup; } - if (virStorageEncryptionInfoParseIvgen(tmpnode, &ret->encinfo)= < 0) + if (virStorageEncryptionInfoParseIvgen(tmpnode, &encdef->encin= fo) < 0) goto cleanup; } } - - return ret; + VIR_STEAL_PTR(ret, encdef); cleanup: VIR_FREE(format_str); VIR_FREE(nodes); - virStorageEncryptionFree(ret); - return NULL; + virStorageEncryptionFree(encdef); + return ret; } virStorageEncryptionPtr --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list