qemuProcessUpdateDevices: Refactor cleanup and memory handling

Use automatic memory freeing and remove the 'cleanup' label. Also make
it a bit more obvious that nothing happens if the 'old' list wasn't
present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-02-03 18:39:01 +01:00
parent ca1899fc45
commit d9f7e87673

View File

@ -3798,32 +3798,23 @@ qemuProcessUpdateDevices(virQEMUDriverPtr driver,
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainDeviceDef dev;
const char **qemuDevices;
char **old;
char **tmp;
int ret = -1;
g_auto(GStrv) old = g_steal_pointer(&priv->qemuDevices);
GStrv tmp;
old = priv->qemuDevices;
priv->qemuDevices = NULL;
if (qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
goto cleanup;
return -1;
qemuDevices = (const char **)priv->qemuDevices;
if ((tmp = old)) {
while (*tmp) {
if (!virStringListHasString(qemuDevices, *tmp) &&
virDomainDefFindDevice(vm->def, *tmp, &dev, false) == 0 &&
qemuDomainRemoveDevice(driver, vm, &dev) < 0) {
goto cleanup;
}
tmp++;
}
if (!old)
return 0;
for (tmp = old; *tmp; tmp++) {
if (!virStringListHasString((const char **) priv->qemuDevices, *tmp) &&
virDomainDefFindDevice(vm->def, *tmp, &dev, false) == 0 &&
qemuDomainRemoveDevice(driver, vm, &dev))
return -1;
}
ret = 0;
cleanup:
g_strfreev(old);
return ret;
return 0;
}
static int