qemuDomainSnapshotLoad: Refactor handling of snapshot definition object

Move the variable holding the snapshot definition into the loop and use
automatic clearing for it. Adjust the code for parity.

Note that the clearing of 'snapdef' on success of
'virDomainSnapshotAssignDef' will be refactored in upcoming patches.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-01-12 16:40:03 +01:00
parent 2d0f7d779d
commit 91df85e057

View File

@ -343,7 +343,6 @@ qemuDomainSnapshotLoad(virDomainObj *vm,
g_autofree char *snapDir = NULL; g_autofree char *snapDir = NULL;
g_autoptr(DIR) dir = NULL; g_autoptr(DIR) dir = NULL;
struct dirent *entry; struct dirent *entry;
virDomainSnapshotDef *def = NULL;
virDomainMomentObj *snap = NULL; virDomainMomentObj *snap = NULL;
virDomainMomentObj *current = NULL; virDomainMomentObj *current = NULL;
bool cur; bool cur;
@ -367,6 +366,7 @@ qemuDomainSnapshotLoad(virDomainObj *vm,
goto cleanup; goto cleanup;
while ((direrr = virDirRead(dir, &entry, NULL)) > 0) { while ((direrr = virDirRead(dir, &entry, NULL)) > 0) {
g_autoptr(virDomainSnapshotDef) snapdef = NULL;
g_autofree char *xmlStr = NULL; g_autofree char *xmlStr = NULL;
g_autofree char *fullpath = NULL; g_autofree char *fullpath = NULL;
@ -384,11 +384,11 @@ qemuDomainSnapshotLoad(virDomainObj *vm,
continue; continue;
} }
def = virDomainSnapshotDefParseString(xmlStr, snapdef = virDomainSnapshotDefParseString(xmlStr,
qemu_driver->xmlopt, qemu_driver->xmlopt,
priv->qemuCaps, &cur, priv->qemuCaps, &cur,
flags); flags);
if (def == NULL) { if (snapdef == NULL) {
/* Nothing we can do here, skip this one */ /* Nothing we can do here, skip this one */
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to parse snapshot XML from file '%s'"), _("Failed to parse snapshot XML from file '%s'"),
@ -396,10 +396,10 @@ qemuDomainSnapshotLoad(virDomainObj *vm,
continue; continue;
} }
snap = virDomainSnapshotAssignDef(vm->snapshots, def); snap = virDomainSnapshotAssignDef(vm->snapshots, snapdef);
if (snap == NULL) { if (snap)
virObjectUnref(def); snapdef = NULL;
} else if (cur) { if (cur && snap) {
if (current) if (current)
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Too many snapshots claiming to be current for domain %s"), _("Too many snapshots claiming to be current for domain %s"),