mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
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:
parent
ca1899fc45
commit
d9f7e87673
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user