From nobody Tue Feb 10 10:59:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646916132; cv=none; d=zohomail.com; s=zohoarc; b=Cl06jz/Ouxd983yEYX7WXH9lCLBYeVv1F44fDLcP6HGMejPnzTRvIBgPQb+z8Py9OfJu1qFlVg5wvnlOcbtLsBWacD4fpctbdPNz+5KaQyU06A5L21NMylNMjrsB/t9Jtk/BOamLWvOHuZ5gVi7SrlNWVHNEZWEVIILiyzHJaHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646916132; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Bj0CDx9JH4o4RGWhofXO8OxPqbHE4Utl+AggwQQ0Mo4=; b=YKvJV2//GPaqYT5LJJme7YiidaGym16iMidHn+pF+xBAEKMoqEnqZCfDHrlwV9drN6sdhB8YAVIQrlCdFNOd6zwIHoZQRENjcOPnNh5RPQc15iiI1ypsEaUB1fAi7bmSr+JNd20br9oD40om6kH8waTBbLTrwo6lkxlg/41l5xY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646916132868126.92974060271865; Thu, 10 Mar 2022 04:42:12 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-397-lqcZN5UZM0i-BhIINqstGw-1; Thu, 10 Mar 2022 07:40:59 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9BF191C168E6; Thu, 10 Mar 2022 12:40:57 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87778463EC6; Thu, 10 Mar 2022 12:40:57 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3E249195FD49; Thu, 10 Mar 2022 12:40:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5AC9A195356C for ; Thu, 10 Mar 2022 12:40:56 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2E83C7B6D8; Thu, 10 Mar 2022 12:40:56 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 906C77D3CE for ; Thu, 10 Mar 2022 12:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646916131; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Bj0CDx9JH4o4RGWhofXO8OxPqbHE4Utl+AggwQQ0Mo4=; b=OHrCgxtJij1pgJl8yV3GlJnzJmllk80unPSUwwh8lRlvxsLWRJBHq3BQuLXYGtLNgfaheK Fi8PcP1egZ6qTjMonZ9anyj97xpnJ/QXA+EpShKLieqiIRlM+fDvOXRD5XdmbRZ9bR3bDx Z0f3O3TBFoX/klbMa3o2Ren/nucJFm8= X-MC-Unique: lqcZN5UZM0i-BhIINqstGw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/14] virDomainSnapshotDefParse: Refactor cleanup Date: Thu, 10 Mar 2022 13:40:38 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646916134931100003 Content-Type: text/plain; charset="utf-8" Use automatic memory cleanup, decrease scope of variables and remove the 'cleanup' label. Signed-off-by: Peter Krempa --- src/conf/snapshot_conf.c | 74 +++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 42 deletions(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index f477b67785..f3b264d2e1 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -216,17 +216,12 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, bool *current, unsigned int flags) { - virDomainSnapshotDef *def =3D NULL; - virDomainSnapshotDef *ret =3D NULL; - xmlNodePtr *nodes =3D NULL; - xmlNodePtr inactiveDomNode =3D NULL; + g_autoptr(virDomainSnapshotDef) def =3D NULL; + g_autofree xmlNodePtr *diskNodes =3D NULL; size_t i; int n; - char *state =3D NULL; - int active; - char *tmp; - char *memorySnapshot =3D NULL; - char *memoryFile =3D NULL; + g_autofree char *memorySnapshot =3D NULL; + g_autofree char *memoryFile =3D NULL; bool offline =3D !!(flags & VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE); virSaveCookieCallbacks *saveCookie =3D virDomainXMLOptionGetSaveCookie= (xmlopt); int domainflags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE | @@ -240,18 +235,22 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) { virReportError(VIR_ERR_XML_ERROR, "%s", _("a redefined snapshot must have a name")); - goto cleanup; + return NULL; } } def->parent.description =3D virXPathString("string(./description)", ct= xt); if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) { + g_autofree char *state =3D NULL; + g_autofree char *domtype =3D NULL; + xmlNodePtr inactiveDomNode =3D NULL; + if (virXPathLongLong("string(./creationTime)", ctxt, &def->parent.creationTime) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing creationTime from existing snapshot"= )); - goto cleanup; + return NULL; } def->parent.parent_name =3D virXPathString("string(./parent/name)"= , ctxt); @@ -263,14 +262,14 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, */ virReportError(VIR_ERR_XML_ERROR, "%s", _("missing state from existing snapshot")); - goto cleanup; + return NULL; } def->state =3D virDomainSnapshotStateTypeFromString(state); if (def->state <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid state '%s' in domain snapshot XML"), state); - goto cleanup; + return NULL; } offline =3D (def->state =3D=3D VIR_DOMAIN_SNAPSHOT_SHUTOFF || def->state =3D=3D VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT); @@ -279,20 +278,19 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, * lack domain/@type. In that case, leave dom NULL, and * clients will have to decide between best effort * initialization or outright failure. */ - if ((tmp =3D virXPathString("string(./domain/@type)", ctxt))) { + if ((domtype =3D virXPathString("string(./domain/@type)", ctxt))) { xmlNodePtr domainNode =3D virXPathNode("./domain", ctxt); - VIR_FREE(tmp); if (!domainNode) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing domain in snapshot")); - goto cleanup; + return NULL; } def->parent.dom =3D virDomainDefParseNode(ctxt->node->doc, dom= ainNode, xmlopt, parseOpaque, domainflags); if (!def->parent.dom) - goto cleanup; + return NULL; } else { VIR_WARN("parsing older snapshot that lacks domain"); } @@ -304,10 +302,10 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, def->parent.inactiveDom =3D virDomainDefParseNode(ctxt->node->= doc, inactiveDomNode, xmlopt, NULL, = domainflags); if (!def->parent.inactiveDom) - goto cleanup; + return NULL; } } else if (virDomainXMLOptionRunMomentPostParse(xmlopt, &def->parent) = < 0) { - goto cleanup; + return NULL; } memorySnapshot =3D virXPathString("string(./memory/@snapshot)", ctxt); @@ -318,20 +316,20 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown memory snapshot setting '%s'"), memorySnapshot); - goto cleanup; + return NULL; } if (memoryFile && def->memory !=3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { virReportError(VIR_ERR_XML_ERROR, _("memory filename '%s' requires external snaps= hot"), memoryFile); - goto cleanup; + return NULL; } if (!memoryFile && def->memory =3D=3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("external memory snapshots require a filename= ")); - goto cleanup; + return NULL; } } else if (memoryFile) { def->memory =3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL; @@ -345,7 +343,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_XML_ERROR, "%s", _("memory state cannot be saved with offline or " "disk-only snapshot")); - goto cleanup; + return NULL; } def->memorysnapshotfile =3D g_steal_pointer(&memoryFile); @@ -354,48 +352,40 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_XML_ERROR, _("memory snapshot file path (%s) must be absolute"= ), def->memorysnapshotfile); - goto cleanup; + return NULL; } - if ((n =3D virXPathNodeSet("./disks/*", ctxt, &nodes)) < 0) - goto cleanup; + if ((n =3D virXPathNodeSet("./disks/*", ctxt, &diskNodes)) < 0) + return NULL; if (n) def->disks =3D g_new0(virDomainSnapshotDiskDef, n); def->ndisks =3D n; for (i =3D 0; i < def->ndisks; i++) { - if (virDomainSnapshotDiskDefParseXML(nodes[i], ctxt, &def->disks[i= ], + if (virDomainSnapshotDiskDefParseXML(diskNodes[i], ctxt, &def->dis= ks[i], flags, xmlopt) < 0) - goto cleanup; + return NULL; } - VIR_FREE(nodes); if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL) { + int active; + if (!current) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("internal parse requested with NULL current")= ); - goto cleanup; + return NULL; } if (virXPathInt("string(./active)", ctxt, &active) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not find 'active' element")); - goto cleanup; + return NULL; } *current =3D active !=3D 0; } if (!offline && virSaveCookieParse(ctxt, &def->cookie, saveCookie) < 0) - goto cleanup; - - ret =3D g_steal_pointer(&def); - - cleanup: - VIR_FREE(state); - VIR_FREE(nodes); - VIR_FREE(memorySnapshot); - VIR_FREE(memoryFile); - virObjectUnref(def); + return NULL; - return ret; + return g_steal_pointer(&def); } virDomainSnapshotDef * --=20 2.35.1