mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virsh: Don't infloop on snapshot/storage_vol failure
Most of our completers used the pattern: if ((nITEM = virITEMListAll()) < 0) return NULL; but the virDomainSnapshot and virStorageVolume completers were instead using goto error. If the ListAll fails with -1, the cleanup label was running a loop of 'size_t i < int nITEM', which is an extreme waste of CPU cycles. Broken since their introduction in v4.1. Fixes:f81f8b62
Fixes:4cb4b649
Reported-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
83b1808ca2
commit
24b092c404
@ -278,6 +278,7 @@ virshStorageVolNameCompleter(vshControl *ctl,
|
|||||||
virshControlPtr priv = ctl->privData;
|
virshControlPtr priv = ctl->privData;
|
||||||
virStoragePoolPtr pool = NULL;
|
virStoragePoolPtr pool = NULL;
|
||||||
virStorageVolPtr *vols = NULL;
|
virStorageVolPtr *vols = NULL;
|
||||||
|
int rc;
|
||||||
int nvols = 0;
|
int nvols = 0;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
char **ret = NULL;
|
char **ret = NULL;
|
||||||
@ -290,8 +291,9 @@ virshStorageVolNameCompleter(vshControl *ctl,
|
|||||||
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((nvols = virStoragePoolListAllVolumes(pool, &vols, flags)) < 0)
|
if ((rc = virStoragePoolListAllVolumes(pool, &vols, flags)) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
nvols = rc;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(ret, nvols + 1) < 0)
|
if (VIR_ALLOC_N(ret, nvols + 1) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -631,6 +633,7 @@ virshSnapshotNameCompleter(vshControl *ctl,
|
|||||||
virshControlPtr priv = ctl->privData;
|
virshControlPtr priv = ctl->privData;
|
||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
virDomainSnapshotPtr *snapshots = NULL;
|
virDomainSnapshotPtr *snapshots = NULL;
|
||||||
|
int rc;
|
||||||
int nsnapshots = 0;
|
int nsnapshots = 0;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
char **ret = NULL;
|
char **ret = NULL;
|
||||||
@ -643,8 +646,9 @@ virshSnapshotNameCompleter(vshControl *ctl,
|
|||||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((nsnapshots = virDomainListAllSnapshots(dom, &snapshots, flags)) < 0)
|
if ((rc = virDomainListAllSnapshots(dom, &snapshots, flags)) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
nsnapshots = rc;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(ret, nsnapshots + 1) < 0)
|
if (VIR_ALLOC_N(ret, nsnapshots + 1) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
Loading…
Reference in New Issue
Block a user