mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
virsh-completer: use g_new0 instead of VIR_ALLOC_N
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
acdac34c45
commit
221f2c0383
@ -50,8 +50,7 @@ virshCheckpointNameCompleter(vshControl *ctl,
|
||||
flags)) < 0)
|
||||
goto error;
|
||||
|
||||
if (VIR_ALLOC_N(ret, ncheckpoints + 1) < 0)
|
||||
goto error;
|
||||
ret = g_new0(char *, ncheckpoints + 1);
|
||||
|
||||
for (i = 0; i < ncheckpoints; i++) {
|
||||
const char *name = virDomainCheckpointGetName(checkpoints[i]);
|
||||
|
@ -61,8 +61,7 @@ virshDomainNameCompleter(vshControl *ctl,
|
||||
if ((ndomains = virConnectListAllDomains(priv->conn, &domains, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, ndomains + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, ndomains + 1);
|
||||
|
||||
for (i = 0; i < ndomains; i++) {
|
||||
const char *name = virDomainGetName(domains[i]);
|
||||
@ -72,7 +71,6 @@ virshDomainNameCompleter(vshControl *ctl,
|
||||
|
||||
ret = g_steal_pointer(&tmp);
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < ndomains; i++)
|
||||
virshDomainFree(domains[i]);
|
||||
g_free(domains);
|
||||
@ -110,8 +108,7 @@ virshDomainUUIDCompleter(vshControl *ctl,
|
||||
if ((ndomains = virConnectListAllDomains(priv->conn, &domains, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, ndomains + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, ndomains + 1);
|
||||
|
||||
for (i = 0; i < ndomains; i++) {
|
||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||
@ -161,8 +158,7 @@ virshDomainInterfaceCompleter(vshControl *ctl,
|
||||
if (ninterfaces < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, ninterfaces + 1) < 0)
|
||||
return NULL;
|
||||
tmp = g_new0(char *, ninterfaces + 1);
|
||||
|
||||
for (i = 0; i < ninterfaces; i++) {
|
||||
ctxt->node = interfaces[i];
|
||||
@ -206,8 +202,7 @@ virshDomainDiskTargetCompleter(vshControl *ctl,
|
||||
if (ndisks < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, ndisks + 1) < 0)
|
||||
return NULL;
|
||||
tmp = g_new0(char *, ndisks + 1);
|
||||
|
||||
for (i = 0; i < ndisks; i++) {
|
||||
ctxt->node = disks[i];
|
||||
@ -229,8 +224,7 @@ virshDomainEventNameCompleter(vshControl *ctl G_GNUC_UNUSED,
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (VIR_ALLOC_N(tmp, VIR_DOMAIN_EVENT_ID_LAST + 1) < 0)
|
||||
return NULL;
|
||||
tmp = g_new0(char *, VIR_DOMAIN_EVENT_ID_LAST + 1);
|
||||
|
||||
for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++)
|
||||
tmp[i] = g_strdup(virshDomainEventCallbacks[i].name);
|
||||
@ -283,8 +277,7 @@ virshDomainInterfaceStateCompleter(vshControl *ctl,
|
||||
|
||||
ctxt->node = interfaces[0];
|
||||
|
||||
if (VIR_ALLOC_N(tmp, 2) < 0)
|
||||
return NULL;
|
||||
tmp = g_new0(char *, 2);
|
||||
|
||||
if ((state = virXPathString("string(./link/@state)", ctxt)) &&
|
||||
STREQ(state, "down")) {
|
||||
@ -326,8 +319,7 @@ virshDomainDeviceAliasCompleter(vshControl *ctl,
|
||||
if (naliases < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, naliases + 1) < 0)
|
||||
return NULL;
|
||||
tmp = g_new0(char *, naliases + 1);
|
||||
|
||||
for (i = 0; i < naliases; i++) {
|
||||
if (!(tmp[i] = virXMLNodeContentString(aliases[i])))
|
||||
@ -404,8 +396,7 @@ virshDomainPerfEnableCompleter(vshControl *ctl,
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (VIR_ALLOC_N(events, VIR_PERF_EVENT_LAST + 1) < 0)
|
||||
return NULL;
|
||||
events = g_new0(char *, VIR_PERF_EVENT_LAST + 1);
|
||||
|
||||
for (i = 0; i < VIR_PERF_EVENT_LAST; i++)
|
||||
events[i] = g_strdup(virPerfEventTypeToString(i));
|
||||
@ -428,8 +419,7 @@ virshDomainPerfDisableCompleter(vshControl *ctl,
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (VIR_ALLOC_N(events, VIR_PERF_EVENT_LAST + 1) < 0)
|
||||
return NULL;
|
||||
events = g_new0(char *, VIR_PERF_EVENT_LAST + 1);
|
||||
|
||||
for (i = 0; i < VIR_PERF_EVENT_LAST; i++)
|
||||
events[i] = g_strdup(virPerfEventTypeToString(i));
|
||||
@ -464,8 +454,7 @@ virshDomainIOThreadIdCompleter(vshControl *ctl,
|
||||
|
||||
niothreads = rc;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, niothreads + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, niothreads + 1);
|
||||
|
||||
for (i = 0; i < niothreads; i++)
|
||||
tmp[i] = g_strdup_printf("%u", info[i]->iothread_id);
|
||||
@ -504,8 +493,7 @@ virshDomainVcpuCompleter(vshControl *ctl,
|
||||
if (virXPathInt("string(/domain/vcpu)", ctxt, &nvcpus) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, nvcpus + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, nvcpus + 1);
|
||||
|
||||
for (id = 0; id < nvcpus; id++)
|
||||
tmp[id] = g_strdup_printf("%u", id);
|
||||
@ -550,8 +538,7 @@ virshDomainVcpulistCompleter(vshControl *ctl,
|
||||
if (virXPathInt("string(/domain/vcpu)", ctxt, &nvcpus) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (VIR_ALLOC_N(vcpulist, nvcpus + 1) < 0)
|
||||
goto cleanup;
|
||||
vcpulist = g_new0(char *, nvcpus + 1);
|
||||
|
||||
for (id = 0; id < nvcpus; id++)
|
||||
vcpulist[id] = g_strdup_printf("%u", id);
|
||||
@ -587,8 +574,7 @@ virshDomainCpulistCompleter(vshControl *ctl,
|
||||
if ((cpunum = virNodeGetCPUMap(priv->conn, &cpumap, &online, 0)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(cpulist, cpunum + 1) < 0)
|
||||
return NULL;
|
||||
cpulist = g_new0(char *, cpunum + 1);
|
||||
|
||||
for (i = 0; i < cpunum; i++)
|
||||
cpulist[i] = g_strdup_printf("%zu", i);
|
||||
|
@ -87,8 +87,7 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl,
|
||||
if (npages <= 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, npages + 1) < 0)
|
||||
return NULL;
|
||||
tmp = g_new0(char *, npages + 1);
|
||||
|
||||
for (i = 0; i < npages; i++) {
|
||||
if (!(tmp[i] = virshPagesizeNodeToString(pages[i])))
|
||||
@ -128,8 +127,7 @@ virshCellnoCompleter(vshControl *ctl,
|
||||
if (ncells <= 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, ncells + 1))
|
||||
return NULL;
|
||||
tmp = g_new0(char *, ncells + 1);
|
||||
|
||||
for (i = 0; i < ncells; i++) {
|
||||
if (!(tmp[i] = virXMLPropString(cells[i], "id")))
|
||||
|
@ -47,8 +47,7 @@ virshInterfaceNameCompleter(vshControl *ctl,
|
||||
if ((nifaces = virConnectListAllInterfaces(priv->conn, &ifaces, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, nifaces + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, nifaces + 1);
|
||||
|
||||
for (i = 0; i < nifaces; i++) {
|
||||
const char *name = virInterfaceGetName(ifaces[i]);
|
||||
@ -58,7 +57,6 @@ virshInterfaceNameCompleter(vshControl *ctl,
|
||||
|
||||
ret = g_steal_pointer(&tmp);
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < nifaces; i++)
|
||||
virInterfaceFree(ifaces[i]);
|
||||
g_free(ifaces);
|
||||
|
@ -49,8 +49,7 @@ virshNetworkNameCompleter(vshControl *ctl,
|
||||
if ((nnets = virConnectListAllNetworks(priv->conn, &nets, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, nnets + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, nnets + 1);
|
||||
|
||||
for (i = 0; i < nnets; i++) {
|
||||
const char *name = virNetworkGetName(nets[i]);
|
||||
@ -60,7 +59,6 @@ virshNetworkNameCompleter(vshControl *ctl,
|
||||
|
||||
ret = g_steal_pointer(&tmp);
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < nnets; i++)
|
||||
virNetworkFree(nets[i]);
|
||||
g_free(nets);
|
||||
@ -78,8 +76,7 @@ virshNetworkEventNameCompleter(vshControl *ctl G_GNUC_UNUSED,
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (VIR_ALLOC_N(tmp, VIR_NETWORK_EVENT_ID_LAST + 1) < 0)
|
||||
return NULL;
|
||||
tmp = g_new0(char *, VIR_NETWORK_EVENT_ID_LAST + 1);
|
||||
|
||||
for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++)
|
||||
tmp[i] = g_strdup(virshNetworkEventCallbacks[i].name);
|
||||
@ -111,8 +108,7 @@ virshNetworkPortUUIDCompleter(vshControl *ctl,
|
||||
if ((nports = virNetworkListAllPorts(net, &ports, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(ret, nports + 1) < 0)
|
||||
goto error;
|
||||
ret = g_new0(char *, nports + 1);
|
||||
|
||||
for (i = 0; i < nports; i++) {
|
||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||
@ -159,8 +155,7 @@ virshNetworkUUIDCompleter(vshControl *ctl,
|
||||
if ((nnets = virConnectListAllNetworks(priv->conn, &nets, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, nnets + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, nnets + 1);
|
||||
|
||||
for (i = 0; i < nnets; i++) {
|
||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||
|
@ -47,8 +47,7 @@ virshNodeDeviceNameCompleter(vshControl *ctl,
|
||||
if ((ndevs = virConnectListAllNodeDevices(priv->conn, &devs, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, ndevs + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, ndevs + 1);
|
||||
|
||||
for (i = 0; i < ndevs; i++) {
|
||||
const char *name = virNodeDeviceGetName(devs[i]);
|
||||
@ -58,7 +57,6 @@ virshNodeDeviceNameCompleter(vshControl *ctl,
|
||||
|
||||
ret = g_steal_pointer(&tmp);
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < ndevs; i++)
|
||||
virNodeDeviceFree(devs[i]);
|
||||
g_free(devs);
|
||||
@ -76,8 +74,7 @@ virshNodeDeviceEventNameCompleter(vshControl *ctl G_GNUC_UNUSED,
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (VIR_ALLOC_N(tmp, VIR_NODE_DEVICE_EVENT_ID_LAST + 1) < 0)
|
||||
return NULL;
|
||||
tmp = g_new0(char *, VIR_NODE_DEVICE_EVENT_ID_LAST + 1);
|
||||
|
||||
for (i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++)
|
||||
tmp[i] = g_strdup(virshNodeDeviceEventCallbacks[i].name);
|
||||
@ -100,8 +97,7 @@ virshNodeDeviceCapabilityNameCompleter(vshControl *ctl,
|
||||
if (vshCommandOptStringQuiet(ctl, cmd, "cap", &cap_str) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, VIR_NODE_DEV_CAP_LAST + 1) < 0)
|
||||
return NULL;
|
||||
tmp = g_new0(char *, VIR_NODE_DEV_CAP_LAST + 1);
|
||||
|
||||
for (i = 0; i < VIR_NODE_DEV_CAP_LAST; i++)
|
||||
tmp[i] = g_strdup(virNodeDevCapTypeToString(i));
|
||||
|
@ -45,8 +45,7 @@ virshNWFilterNameCompleter(vshControl *ctl,
|
||||
if ((nnwfilters = virConnectListAllNWFilters(priv->conn, &nwfilters, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, nnwfilters + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, nnwfilters + 1);
|
||||
|
||||
for (i = 0; i < nnwfilters; i++) {
|
||||
const char *name = virNWFilterGetName(nwfilters[i]);
|
||||
@ -56,7 +55,6 @@ virshNWFilterNameCompleter(vshControl *ctl,
|
||||
|
||||
ret = g_steal_pointer(&tmp);
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < nnwfilters; i++)
|
||||
virNWFilterFree(nwfilters[i]);
|
||||
g_free(nwfilters);
|
||||
@ -84,8 +82,7 @@ virshNWFilterBindingNameCompleter(vshControl *ctl,
|
||||
if ((nbindings = virConnectListAllNWFilterBindings(priv->conn, &bindings, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, nbindings + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, nbindings + 1);
|
||||
|
||||
for (i = 0; i < nbindings; i++) {
|
||||
const char *name = virNWFilterBindingGetPortDev(bindings[i]);
|
||||
@ -95,7 +92,6 @@ virshNWFilterBindingNameCompleter(vshControl *ctl,
|
||||
|
||||
ret = g_steal_pointer(&tmp);
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < nbindings; i++)
|
||||
virNWFilterBindingFree(bindings[i]);
|
||||
g_free(bindings);
|
||||
|
@ -50,8 +50,7 @@ virshStoragePoolNameCompleter(vshControl *ctl,
|
||||
if ((npools = virConnectListAllStoragePools(priv->conn, &pools, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, npools + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, npools + 1);
|
||||
|
||||
for (i = 0; i < npools; i++) {
|
||||
const char *name = virStoragePoolGetName(pools[i]);
|
||||
@ -61,7 +60,6 @@ virshStoragePoolNameCompleter(vshControl *ctl,
|
||||
|
||||
ret = g_steal_pointer(&tmp);
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < npools; i++)
|
||||
virStoragePoolFree(pools[i]);
|
||||
g_free(pools);
|
||||
@ -79,8 +77,7 @@ virshPoolEventNameCompleter(vshControl *ctl G_GNUC_UNUSED,
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_EVENT_ID_LAST + 1) < 0)
|
||||
return NULL;
|
||||
tmp = g_new0(char *, VIR_STORAGE_POOL_EVENT_ID_LAST + 1);
|
||||
|
||||
for (i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++)
|
||||
tmp[i] = g_strdup(virshPoolEventCallbacks[i].name);
|
||||
@ -103,8 +100,7 @@ virshPoolTypeCompleter(vshControl *ctl,
|
||||
if (vshCommandOptStringQuiet(ctl, cmd, "type", &type_str) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_LAST + 1) < 0)
|
||||
return NULL;
|
||||
tmp = g_new0(char *, VIR_STORAGE_POOL_LAST + 1);
|
||||
|
||||
for (i = 0; i < VIR_STORAGE_POOL_LAST; i++)
|
||||
tmp[i] = g_strdup(virStoragePoolTypeToString(i));
|
||||
|
@ -47,8 +47,7 @@ virshSecretUUIDCompleter(vshControl *ctl,
|
||||
if ((nsecrets = virConnectListAllSecrets(priv->conn, &secrets, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, nsecrets + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, nsecrets + 1);
|
||||
|
||||
for (i = 0; i < nsecrets; i++) {
|
||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||
@ -78,8 +77,7 @@ virshSecretEventNameCompleter(vshControl *ctl G_GNUC_UNUSED,
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (VIR_ALLOC_N(tmp, VIR_SECRET_EVENT_ID_LAST + 1) < 0)
|
||||
return NULL;
|
||||
tmp = g_new0(char *, VIR_SECRET_EVENT_ID_LAST + 1);
|
||||
|
||||
for (i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++)
|
||||
tmp[i] = g_strdup(virshSecretEventCallbacks[i].name);
|
||||
|
@ -52,8 +52,7 @@ virshSnapshotNameCompleter(vshControl *ctl,
|
||||
goto cleanup;
|
||||
nsnapshots = rc;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, nsnapshots + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, nsnapshots + 1);
|
||||
|
||||
for (i = 0; i < nsnapshots; i++) {
|
||||
const char *name = virDomainSnapshotGetName(snapshots[i]);
|
||||
|
@ -52,8 +52,7 @@ virshStorageVolNameCompleter(vshControl *ctl,
|
||||
goto cleanup;
|
||||
nvols = rc;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, nvols + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp = g_new0(char *, nvols + 1);
|
||||
|
||||
for (i = 0; i < nvols; i++) {
|
||||
const char *name = virStorageVolGetName(vols[i]);
|
||||
|
@ -111,8 +111,7 @@ virshCommaStringListComplete(const char *input,
|
||||
if (inputCopy && !(inputList = virStringSplit(inputCopy, ",", 0)))
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(ret, optionsLen + 1) < 0)
|
||||
return NULL;
|
||||
ret = g_new0(char *, optionsLen + 1);
|
||||
|
||||
for (i = 0; i < optionsLen; i++) {
|
||||
if (virStringListHasString((const char **)inputList, options[i]))
|
||||
|
Loading…
Reference in New Issue
Block a user