virsh: Invert logic in cmdVcpuinfo

Initialize 'ret' to false and introduce a cleanup label.
This commit is contained in:
Ján Tomko 2014-06-05 10:42:19 +02:00
parent 4d06af97d3
commit bec105e6db

View File

@ -5536,25 +5536,21 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainInfo info; virDomainInfo info;
virDomainPtr dom; virDomainPtr dom;
virVcpuInfoPtr cpuinfo; virVcpuInfoPtr cpuinfo = NULL;
unsigned char *cpumaps; unsigned char *cpumaps = NULL;
int ncpus, maxcpu; int ncpus, maxcpu;
size_t cpumaplen; size_t cpumaplen;
bool ret = true; bool ret = false;
int n, m; int n, m;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false; return false;
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) { if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
virDomainFree(dom); goto cleanup;
return false;
}
if (virDomainGetInfo(dom, &info) != 0) { if (virDomainGetInfo(dom, &info) != 0)
virDomainFree(dom); goto cleanup;
return false;
}
cpuinfo = vshMalloc(ctl, sizeof(virVcpuInfo)*info.nrVirtCpu); cpuinfo = vshMalloc(ctl, sizeof(virVcpuInfo)*info.nrVirtCpu);
cpumaplen = VIR_CPU_MAPLEN(maxcpu); cpumaplen = VIR_CPU_MAPLEN(maxcpu);
@ -5608,10 +5604,13 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
} }
} }
} else { } else {
ret = false; goto cleanup;
} }
} }
ret = true;
cleanup:
VIR_FREE(cpumaps); VIR_FREE(cpumaps);
VIR_FREE(cpuinfo); VIR_FREE(cpuinfo);
virDomainFree(dom); virDomainFree(dom);