[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt PATCH 3/3] virsh-completer: use g_new0 instead of VIR_ALLOC_N



Signed-off-by: Ján Tomko <jtomko redhat com>
---
 tools/virsh-completer-checkpoint.c |  3 +--
 tools/virsh-completer-domain.c     | 40 ++++++++++--------------------
 tools/virsh-completer-host.c       |  6 ++---
 tools/virsh-completer-interface.c  |  4 +--
 tools/virsh-completer-network.c    | 13 +++-------
 tools/virsh-completer-nodedev.c    | 10 +++-----
 tools/virsh-completer-nwfilter.c   |  8 ++----
 tools/virsh-completer-pool.c       | 10 +++-----
 tools/virsh-completer-secret.c     |  6 ++---
 tools/virsh-completer-snapshot.c   |  3 +--
 tools/virsh-completer-volume.c     |  3 +--
 tools/virsh-completer.c            |  3 +--
 12 files changed, 34 insertions(+), 75 deletions(-)

diff --git a/tools/virsh-completer-checkpoint.c b/tools/virsh-completer-checkpoint.c
index 0b5af2fa6b..29d644dad0 100644
--- a/tools/virsh-completer-checkpoint.c
+++ b/tools/virsh-completer-checkpoint.c
@@ -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]);
diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
index 8159a0a58d..50a8a31fcd 100644
--- a/tools/virsh-completer-domain.c
+++ b/tools/virsh-completer-domain.c
@@ -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);
diff --git a/tools/virsh-completer-host.c b/tools/virsh-completer-host.c
index 8893888ec2..339390aa00 100644
--- a/tools/virsh-completer-host.c
+++ b/tools/virsh-completer-host.c
@@ -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")))
diff --git a/tools/virsh-completer-interface.c b/tools/virsh-completer-interface.c
index 6ac11a402f..8028db8746 100644
--- a/tools/virsh-completer-interface.c
+++ b/tools/virsh-completer-interface.c
@@ -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);
diff --git a/tools/virsh-completer-network.c b/tools/virsh-completer-network.c
index c29d367c76..a63d657477 100644
--- a/tools/virsh-completer-network.c
+++ b/tools/virsh-completer-network.c
@@ -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];
diff --git a/tools/virsh-completer-nodedev.c b/tools/virsh-completer-nodedev.c
index 94da5965f2..a9fc37733c 100644
--- a/tools/virsh-completer-nodedev.c
+++ b/tools/virsh-completer-nodedev.c
@@ -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));
diff --git a/tools/virsh-completer-nwfilter.c b/tools/virsh-completer-nwfilter.c
index a3fbeded29..b1aa084b49 100644
--- a/tools/virsh-completer-nwfilter.c
+++ b/tools/virsh-completer-nwfilter.c
@@ -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);
diff --git a/tools/virsh-completer-pool.c b/tools/virsh-completer-pool.c
index 35eeed6043..ecf2514a59 100644
--- a/tools/virsh-completer-pool.c
+++ b/tools/virsh-completer-pool.c
@@ -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));
diff --git a/tools/virsh-completer-secret.c b/tools/virsh-completer-secret.c
index 568599c6e4..940d65a322 100644
--- a/tools/virsh-completer-secret.c
+++ b/tools/virsh-completer-secret.c
@@ -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);
diff --git a/tools/virsh-completer-snapshot.c b/tools/virsh-completer-snapshot.c
index 9ab74bb471..f6aa405ea3 100644
--- a/tools/virsh-completer-snapshot.c
+++ b/tools/virsh-completer-snapshot.c
@@ -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]);
diff --git a/tools/virsh-completer-volume.c b/tools/virsh-completer-volume.c
index 296e67dd71..29330f5bd8 100644
--- a/tools/virsh-completer-volume.c
+++ b/tools/virsh-completer-volume.c
@@ -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]);
diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index bb6550ee63..08f3825e89 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -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]))
-- 
2.26.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]