From b326b4eeaa596f17ba0498dcaa2363d9fd469227 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 30 Nov 2021 13:16:15 +0100 Subject: [PATCH] qemuCheckpointGetXMLDescUpdateSize: Don't combine automatic freeing with manual MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'blockNamedNodeData' is declared for automatic freeing but we also free it manually and reuse which is a code pattern we don't normally allow. Rewrite the code to have actually two separate hash tables. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko Reviewed-by: Martin Kletzander --- src/qemu/qemu_checkpoint.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c index 3ac5912def..69f287399b 100644 --- a/src/qemu/qemu_checkpoint.c +++ b/src/qemu/qemu_checkpoint.c @@ -647,7 +647,8 @@ qemuCheckpointGetXMLDescUpdateSize(virDomainObj *vm, { qemuDomainObjPrivate *priv = vm->privateData; virQEMUDriver *driver = priv->driver; - g_autoptr(GHashTable) blockNamedNodeData = NULL; + g_autoptr(GHashTable) nodedataMerge = NULL; + g_autoptr(GHashTable) nodedataStats = NULL; g_autofree struct qemuCheckpointDiskMap *diskmap = NULL; g_autoptr(virJSONValue) recoveractions = NULL; g_autoptr(virJSONValue) mergeactions = virJSONValueNewArray(); @@ -663,7 +664,7 @@ qemuCheckpointGetXMLDescUpdateSize(virDomainObj *vm, if (virDomainObjCheckActive(vm) < 0) goto endjob; - if (!(blockNamedNodeData = qemuBlockGetNamedNodeData(vm, QEMU_ASYNC_JOB_NONE))) + if (!(nodedataMerge = qemuBlockGetNamedNodeData(vm, QEMU_ASYNC_JOB_NONE))) goto endjob; /* enumerate disks relevant for the checkpoint which are also present in the @@ -683,7 +684,7 @@ qemuCheckpointGetXMLDescUpdateSize(virDomainObj *vm, if (!(domdisk = virDomainDiskByTarget(vm->def, chkdisk->name))) continue; - if (!qemuBlockBitmapChainIsValid(domdisk->src, chkdef->parent.name, blockNamedNodeData)) + if (!qemuBlockBitmapChainIsValid(domdisk->src, chkdef->parent.name, nodedataMerge)) continue; diskmap[ndisks].chkdisk = chkdisk; @@ -702,7 +703,7 @@ qemuCheckpointGetXMLDescUpdateSize(virDomainObj *vm, g_autoptr(virJSONValue) actions = NULL; /* possibly delete leftovers from previous cases */ - if (qemuBlockNamedNodeDataGetBitmapByName(blockNamedNodeData, domdisk->src, + if (qemuBlockNamedNodeDataGetBitmapByName(nodedataMerge, domdisk->src, "libvirt-tmp-size-xml")) { if (!recoveractions) recoveractions = virJSONValueNewArray(); @@ -715,7 +716,7 @@ qemuCheckpointGetXMLDescUpdateSize(virDomainObj *vm, if (qemuBlockGetBitmapMergeActions(domdisk->src, NULL, domdisk->src, chkdef->parent.name, "libvirt-tmp-size-xml", - NULL, &actions, blockNamedNodeData) < 0) + NULL, &actions, nodedataMerge) < 0) goto endjob; if (virJSONValueArrayConcat(mergeactions, actions) < 0) @@ -740,8 +741,7 @@ qemuCheckpointGetXMLDescUpdateSize(virDomainObj *vm, goto endjob; /* now do a final refresh */ - virHashFree(blockNamedNodeData); - if (!(blockNamedNodeData = qemuBlockGetNamedNodeData(vm, QEMU_ASYNC_JOB_NONE))) + if (!(nodedataStats = qemuBlockGetNamedNodeData(vm, QEMU_ASYNC_JOB_NONE))) goto endjob; qemuDomainObjEnterMonitor(driver, vm); @@ -758,7 +758,7 @@ qemuCheckpointGetXMLDescUpdateSize(virDomainObj *vm, virDomainDiskDef *domdisk = diskmap[i].domdisk; qemuBlockNamedNodeDataBitmap *bitmap; - if ((bitmap = qemuBlockNamedNodeDataGetBitmapByName(blockNamedNodeData, domdisk->src, + if ((bitmap = qemuBlockNamedNodeDataGetBitmapByName(nodedataStats, domdisk->src, "libvirt-tmp-size-xml"))) { chkdisk->size = bitmap->dirtybytes; chkdisk->sizeValid = true;