[libvirt PATCH 3/8] remote: use g_new0 instead of VIR_ALLOC

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

 



Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/remote/remote_daemon_config.c   |   3 +-
 src/remote/remote_daemon_dispatch.c | 225 ++++++++++------------------
 src/remote/remote_daemon_stream.c   |   6 +-
 src/remote/remote_driver.c          | 102 ++++---------
 4 files changed, 108 insertions(+), 228 deletions(-)

diff --git a/src/remote/remote_daemon_config.c b/src/remote/remote_daemon_config.c
index a09f287656..f0cca42925 100644
--- a/src/remote/remote_daemon_config.c
+++ b/src/remote/remote_daemon_config.c
@@ -94,8 +94,7 @@ daemonConfigNew(bool privileged G_GNUC_UNUSED)
 {
     struct daemonConfig *data;
 
-    if (VIR_ALLOC(data) < 0)
-        return NULL;
+    data = g_new0(struct daemonConfig, 1);
 
 #ifdef WITH_IP
 # ifdef LIBVIRTD
diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
index a659737bc7..90115167fb 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -1597,8 +1597,7 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr conn,
     data.seconds = seconds;
     data.micros = micros;
     if (details) {
-        if (VIR_ALLOC(data.details) < 0)
-            goto error;
+        data.details = g_new0(char *, 1);
         *(data.details) = g_strdup(details);
     }
     make_nonnull_domain(&data.dom, dom);
@@ -1608,11 +1607,6 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr conn,
                                   (xdrproc_t)xdr_qemu_domain_monitor_event_msg,
                                   &data);
     return;
-
- error:
-    xdr_free((xdrproc_t)xdr_qemu_domain_monitor_event_msg,
-             (char *) &data);
-    return;
 }
 
 static
@@ -1907,8 +1901,7 @@ void *remoteClientNew(virNetServerClientPtr client,
 {
     struct daemonClientPrivate *priv;
 
-    if (VIR_ALLOC(priv) < 0)
-        return NULL;
+    priv = g_new0(struct daemonClientPrivate, 1);
 
     if (virMutexInit(&priv->lock) < 0) {
         VIR_FREE(priv);
@@ -2309,8 +2302,8 @@ remoteDispatchDomainGetSchedulerParameters(virNetServerPtr server G_GNUC_UNUSED,
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
         goto cleanup;
     }
-    if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
-        goto cleanup;
+    if (args->nparams)
+        params = g_new0(virTypedParameter, args->nparams);
     nparams = args->nparams;
 
     if (!(dom = get_nonnull_domain(conn, args->dom)))
@@ -2357,8 +2350,8 @@ remoteDispatchDomainGetSchedulerParametersFlags(virNetServerPtr server G_GNUC_UN
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
         goto cleanup;
     }
-    if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
-        goto cleanup;
+    if (args->nparams)
+        params = g_new0(virTypedParameter, args->nparams);
     nparams = args->nparams;
 
     if (!(dom = get_nonnull_domain(conn, args->dom)))
@@ -2413,16 +2406,14 @@ remoteDispatchDomainMemoryStats(virNetServerPtr server G_GNUC_UNUSED,
         goto cleanup;
 
     /* Allocate stats array for making dispatch call */
-    if (VIR_ALLOC_N(stats, args->maxStats) < 0)
-        goto cleanup;
+    stats = g_new0(struct _virDomainMemoryStat, args->maxStats);
 
     nr_stats = virDomainMemoryStats(dom, stats, args->maxStats, args->flags);
     if (nr_stats < 0)
         goto cleanup;
 
     /* Allocate return buffer */
-    if (VIR_ALLOC_N(ret->stats.stats_val, args->maxStats) < 0)
-        goto cleanup;
+    ret->stats.stats_val = g_new0(remote_domain_memory_stat, args->maxStats);
 
     /* Copy the stats into the xdr return structure */
     for (i = 0; i < nr_stats; i++) {
@@ -2473,8 +2464,7 @@ remoteDispatchDomainBlockPeek(virNetServerPtr server G_GNUC_UNUSED,
     }
 
     ret->buffer.buffer_len = size;
-    if (VIR_ALLOC_N(ret->buffer.buffer_val, size) < 0)
-        goto cleanup;
+    ret->buffer.buffer_val = g_new0(char, size);
 
     if (virDomainBlockPeek(dom, path, offset, size,
                            ret->buffer.buffer_val, flags) < 0)
@@ -2518,8 +2508,8 @@ remoteDispatchDomainBlockStatsFlags(virNetServerPtr server G_GNUC_UNUSED,
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
         goto cleanup;
     }
-    if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
-        goto cleanup;
+    if (args->nparams)
+        params = g_new0(virTypedParameter, args->nparams);
     nparams = args->nparams;
 
     if (virDomainBlockStatsFlags(dom, path, params, &nparams, flags) < 0)
@@ -2583,8 +2573,7 @@ remoteDispatchDomainMemoryPeek(virNetServerPtr server G_GNUC_UNUSED,
     }
 
     ret->buffer.buffer_len = size;
-    if (VIR_ALLOC_N(ret->buffer.buffer_val, size) < 0)
-        goto cleanup;
+    ret->buffer.buffer_val = g_new0(char, size);
 
     if (virDomainMemoryPeek(dom, offset, size,
                             ret->buffer.buffer_val, flags) < 0)
@@ -2620,15 +2609,13 @@ remoteDispatchDomainGetSecurityLabel(virNetServerPtr server G_GNUC_UNUSED,
     if (!(dom = get_nonnull_domain(conn, args->dom)))
         goto cleanup;
 
-    if (VIR_ALLOC(seclabel) < 0)
-        goto cleanup;
+    seclabel = g_new0(virSecurityLabel, 1);
 
     if (virDomainGetSecurityLabel(dom, seclabel) < 0)
         goto cleanup;
 
     ret->label.label_len = strlen(seclabel->label) + 1;
-    if (VIR_ALLOC_N(ret->label.label_val, ret->label.label_len) < 0)
-        goto cleanup;
+    ret->label.label_val = g_new0(char, ret->label.label_len);
     strcpy(ret->label.label_val, seclabel->label);
     ret->enforcing = seclabel->enforcing;
 
@@ -2669,8 +2656,7 @@ remoteDispatchDomainGetSecurityLabelList(virNetServerPtr server G_GNUC_UNUSED,
         goto done;
     }
 
-    if (VIR_ALLOC_N(ret->labels.labels_val, len) < 0)
-        goto cleanup;
+    ret->labels.labels_val = g_new0(remote_domain_get_security_label_ret, len);
 
     for (i = 0; i < len; i++) {
         size_t label_len = strlen(seclabels[i].label) + 1;
@@ -2711,13 +2697,11 @@ remoteDispatchNodeGetSecurityModel(virNetServerPtr server G_GNUC_UNUSED,
         goto cleanup;
 
     ret->model.model_len = strlen(secmodel.model) + 1;
-    if (VIR_ALLOC_N(ret->model.model_val, ret->model.model_len) < 0)
-        goto cleanup;
+    ret->model.model_val = g_new0(char, ret->model.model_len);
     strcpy(ret->model.model_val, secmodel.model);
 
     ret->doi.doi_len = strlen(secmodel.doi) + 1;
-    if (VIR_ALLOC_N(ret->doi.doi_val, ret->doi.doi_len) < 0)
-        goto cleanup;
+    ret->doi.doi_val = g_new0(char, ret->doi.doi_len);
     strcpy(ret->doi.doi_val, secmodel.doi);
 
     rv = 0;
@@ -2760,9 +2744,8 @@ remoteDispatchDomainGetVcpuPinInfo(virNetServerPtr server G_GNUC_UNUSED,
     }
 
     /* Allocate buffers to take the results. */
-    if (args->maplen > 0 &&
-        VIR_ALLOC_N(cpumaps, args->ncpumaps * args->maplen) < 0)
-        goto cleanup;
+    if (args->maplen > 0)
+        cpumaps = g_new0(unsigned char, args->ncpumaps * args->maplen);
 
     if ((num = virDomainGetVcpuPinInfo(dom,
                                        args->ncpumaps,
@@ -2844,9 +2827,8 @@ remoteDispatchDomainGetEmulatorPinInfo(virNetServerPtr server G_GNUC_UNUSED,
         goto cleanup;
 
     /* Allocate buffers to take the results */
-    if (args->maplen > 0 &&
-        VIR_ALLOC_N(cpumaps, args->maplen) < 0)
-        goto cleanup;
+    if (args->maplen > 0)
+        cpumaps = g_new0(unsigned char, args->maplen);
 
     if ((r = virDomainGetEmulatorPinInfo(dom,
                                          cpumaps,
@@ -2903,11 +2885,9 @@ remoteDispatchDomainGetVcpus(virNetServerPtr server G_GNUC_UNUSED,
     }
 
     /* Allocate buffers to take the results. */
-    if (VIR_ALLOC_N(info, args->maxinfo) < 0)
-        goto cleanup;
-    if (args->maplen > 0 &&
-        VIR_ALLOC_N(cpumaps, args->maxinfo * args->maplen) < 0)
-        goto cleanup;
+    info = g_new0(virVcpuInfo, args->maxinfo);
+    if (args->maplen > 0)
+        cpumaps = g_new0(unsigned char, args->maxinfo * args->maplen);
 
     if ((info_len = virDomainGetVcpus(dom,
                                       info, args->maxinfo,
@@ -2916,8 +2896,7 @@ remoteDispatchDomainGetVcpus(virNetServerPtr server G_GNUC_UNUSED,
 
     /* Allocate the return buffer for info. */
     ret->info.info_len = info_len;
-    if (VIR_ALLOC_N(ret->info.info_val, info_len) < 0)
-        goto cleanup;
+    ret->info.info_val = g_new0(remote_vcpu_info, info_len);
 
     for (i = 0; i < info_len; ++i) {
         ret->info.info_val[i].number = info[i].number;
@@ -2980,9 +2959,7 @@ remoteDispatchDomainGetIOThreadInfo(virNetServerPtr server G_GNUC_UNUSED,
     }
 
     if (ninfo) {
-        if (VIR_ALLOC_N(ret->info.info_val, ninfo) < 0)
-            goto cleanup;
-
+        ret->info.info_val = g_new0(remote_domain_iothread_info, ninfo);
         ret->info.info_len = ninfo;
 
         for (i = 0; i < ninfo; i++) {
@@ -3040,8 +3017,7 @@ remoteDispatchDomainMigratePrepare(virNetServerPtr server G_GNUC_UNUSED,
     dname = args->dname == NULL ? NULL : *args->dname;
 
     /* Wacky world of XDR ... */
-    if (VIR_ALLOC(uri_out) < 0)
-        goto cleanup;
+    uri_out = g_new0(char *, 1);
 
     if (virDomainMigratePrepare(conn, &cookie, &cookielen,
                                 uri_in, uri_out,
@@ -3092,8 +3068,7 @@ remoteDispatchDomainMigratePrepare2(virNetServerPtr server G_GNUC_UNUSED,
     dname = args->dname == NULL ? NULL : *args->dname;
 
     /* Wacky world of XDR ... */
-    if (VIR_ALLOC(uri_out) < 0)
-        goto cleanup;
+    uri_out = g_new0(char *, 1);
 
     if (virDomainMigratePrepare2(conn, &cookie, &cookielen,
                                  uri_in, uri_out,
@@ -3142,8 +3117,8 @@ remoteDispatchDomainGetMemoryParameters(virNetServerPtr server G_GNUC_UNUSED,
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
         goto cleanup;
     }
-    if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
-        goto cleanup;
+    if (args->nparams)
+        params = g_new0(virTypedParameter, args->nparams);
     nparams = args->nparams;
 
     if (!(dom = get_nonnull_domain(conn, args->dom)))
@@ -3202,8 +3177,8 @@ remoteDispatchDomainGetNumaParameters(virNetServerPtr server G_GNUC_UNUSED,
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
         goto cleanup;
     }
-    if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
-        goto cleanup;
+    if (args->nparams)
+        params = g_new0(virTypedParameter, args->nparams);
     nparams = args->nparams;
 
     if (!(dom = get_nonnull_domain(conn, args->dom)))
@@ -3262,8 +3237,8 @@ remoteDispatchDomainGetBlkioParameters(virNetServerPtr server G_GNUC_UNUSED,
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
         goto cleanup;
     }
-    if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
-        goto cleanup;
+    if (args->nparams)
+        params = g_new0(virTypedParameter, args->nparams);
     nparams = args->nparams;
 
     if (!(dom = get_nonnull_domain(conn, args->dom)))
@@ -3323,8 +3298,8 @@ remoteDispatchNodeGetCPUStats(virNetServerPtr server G_GNUC_UNUSED,
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
         goto cleanup;
     }
-    if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
-        goto cleanup;
+    if (args->nparams)
+        params = g_new0(virNodeCPUStats, args->nparams);
     nparams = args->nparams;
 
     if (virNodeGetCPUStats(conn, cpuNum, params, &nparams, flags) < 0)
@@ -3340,8 +3315,7 @@ remoteDispatchNodeGetCPUStats(virNetServerPtr server G_GNUC_UNUSED,
 
     /* Serialise the memory parameters. */
     ret->params.params_len = nparams;
-    if (VIR_ALLOC_N(ret->params.params_val, nparams) < 0)
-        goto cleanup;
+    ret->params.params_val = g_new0(remote_node_get_cpu_stats, nparams);
 
     for (i = 0; i < nparams; ++i) {
         /* remoteDispatchClientRequest will free this: */
@@ -3391,8 +3365,8 @@ remoteDispatchNodeGetMemoryStats(virNetServerPtr server G_GNUC_UNUSED,
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
         goto cleanup;
     }
-    if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
-        goto cleanup;
+    if (args->nparams)
+        params = g_new0(virNodeMemoryStats, args->nparams);
     nparams = args->nparams;
 
     if (virNodeGetMemoryStats(conn, cellNum, params, &nparams, flags) < 0)
@@ -3408,8 +3382,7 @@ remoteDispatchNodeGetMemoryStats(virNetServerPtr server G_GNUC_UNUSED,
 
     /* Serialise the memory parameters. */
     ret->params.params_len = nparams;
-    if (VIR_ALLOC_N(ret->params.params_val, nparams) < 0)
-        goto cleanup;
+    ret->params.params_val = g_new0(remote_node_get_memory_stats, nparams);
 
     for (i = 0; i < nparams; ++i) {
         /* remoteDispatchClientRequest will free this: */
@@ -3573,8 +3546,8 @@ remoteDispatchDomainGetBlockIoTune(virNetServerPtr server G_GNUC_UNUSED,
         goto cleanup;
     }
 
-    if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
-        goto cleanup;
+    if (args->nparams)
+        params = g_new0(virTypedParameter, args->nparams);
     nparams = args->nparams;
 
     if (!(dom = get_nonnull_domain(conn, args->dom)))
@@ -3649,8 +3622,7 @@ remoteDispatchAuthList(virNetServerPtr server,
     }
 
     ret->types.types_len = 1;
-    if (VIR_ALLOC_N(ret->types.types_val, ret->types.types_len) < 0)
-        goto cleanup;
+    ret->types.types_val = g_new0(remote_auth_type, ret->types.types_len);
 
     switch ((virNetServerServiceAuthMethods) auth) {
     case VIR_NET_SERVER_SERVICE_AUTH_NONE:
@@ -3666,7 +3638,6 @@ remoteDispatchAuthList(virNetServerPtr server,
 
     rv = 0;
 
- cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
     return rv;
@@ -3846,8 +3817,7 @@ remoteDispatchAuthSaslStart(virNetServerPtr server,
 
     /* NB, distinction of NULL vs "" is *critical* in SASL */
     if (serverout) {
-        if (VIR_ALLOC_N(ret->data.data_val, serveroutlen) < 0)
-            goto authfail;
+        ret->data.data_val = g_new0(char, serveroutlen);
         memcpy(ret->data.data_val, serverout, serveroutlen);
     } else {
         ret->data.data_val = NULL;
@@ -3942,8 +3912,7 @@ remoteDispatchAuthSaslStep(virNetServerPtr server,
 
     /* NB, distinction of NULL vs "" is *critical* in SASL */
     if (serverout) {
-        if (VIR_ALLOC_N(ret->data.data_val, serveroutlen) < 0)
-            goto authfail;
+        ret->data.data_val = g_new0(char, serveroutlen);
         memcpy(ret->data.data_val, serverout, serveroutlen);
     } else {
         ret->data.data_val = NULL;
@@ -4147,8 +4116,7 @@ remoteDispatchNodeDeviceGetParent(virNetServerPtr server G_GNUC_UNUSED,
         ret->parentName = NULL;
     } else {
         /* remoteDispatchClientRequest will free this. */
-        if (VIR_ALLOC(ret->parentName) < 0)
-            goto cleanup;
+        ret->parentName = g_new0(char *, 1);
         *(ret->parentName) = g_strdup(parent);
     }
 
@@ -4250,8 +4218,7 @@ remoteDispatchConnectDomainEventRegister(virNetServerPtr server G_GNUC_UNUSED,
      * clearing 'callback' and having to juggle the pointer
      * between 'ref' and 'callback'.
      */
-    if (VIR_ALLOC(callback) < 0)
-        goto cleanup;
+    callback = g_new0(daemonClientEventCallback, 1);
     callback->client = virObjectRef(client);
     callback->program = virObjectRef(remoteProgram);
     callback->eventID = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
@@ -4479,8 +4446,7 @@ remoteDispatchConnectDomainEventRegisterAny(virNetServerPtr server G_GNUC_UNUSED
      * incomplete callback to our array, then register, then fix up
      * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on
      * success, we use 'ref' to save a copy of the pointer.  */
-    if (VIR_ALLOC(callback) < 0)
-        goto cleanup;
+    callback = g_new0(daemonClientEventCallback, 1);
     callback->client = virObjectRef(client);
     callback->program = virObjectRef(remoteProgram);
     callback->eventID = args->eventID;
@@ -4555,8 +4521,7 @@ remoteDispatchConnectDomainEventCallbackRegisterAny(virNetServerPtr server G_GNU
      * incomplete callback to our array, then register, then fix up
      * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on
      * success, we use 'ref' to save a copy of the pointer.  */
-    if (VIR_ALLOC(callback) < 0)
-        goto cleanup;
+    callback = g_new0(daemonClientEventCallback, 1);
     callback->client = virObjectRef(client);
     callback->program = virObjectRef(remoteProgram);
     callback->eventID = args->eventID;
@@ -4799,8 +4764,7 @@ remoteDispatchDomainMigratePrepare3(virNetServerPtr server G_GNUC_UNUSED,
     dname = args->dname == NULL ? NULL : *args->dname;
 
     /* Wacky world of XDR ... */
-    if (VIR_ALLOC(uri_out) < 0)
-        goto cleanup;
+    uri_out = g_new0(char *, 1);
 
     if (virDomainMigratePrepare3(conn,
                                  args->cookie_in.cookie_in_val,
@@ -5130,8 +5094,8 @@ remoteDispatchDomainGetInterfaceParameters(virNetServerPtr server G_GNUC_UNUSED,
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
         goto cleanup;
     }
-    if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
-        goto cleanup;
+    if (args->nparams)
+        params = g_new0(virTypedParameter, args->nparams);
     nparams = args->nparams;
 
     if (!(dom = get_nonnull_domain(conn, args->dom)))
@@ -5192,9 +5156,8 @@ remoteDispatchDomainGetCPUStats(virNetServerPtr server G_GNUC_UNUSED,
         goto cleanup;
     }
 
-    if (args->nparams > 0 &&
-        VIR_ALLOC_N(params, args->ncpus * args->nparams) < 0)
-        goto cleanup;
+    if (args->nparams > 0)
+        params = g_new0(virTypedParameter, args->ncpus * args->nparams);
 
     if (!(dom = get_nonnull_domain(conn, args->dom)))
         goto cleanup;
@@ -5261,9 +5224,8 @@ remoteDispatchDomainGetDiskErrors(virNetServerPtr server G_GNUC_UNUSED,
         goto cleanup;
     }
 
-    if (args->maxerrors &&
-        VIR_ALLOC_N(errors, args->maxerrors) < 0)
-        goto cleanup;
+    if (args->maxerrors)
+        errors = g_new0(virDomainDiskError, args->maxerrors);
 
     if ((len = virDomainGetDiskErrors(dom, errors,
                                       args->maxerrors,
@@ -5352,8 +5314,8 @@ remoteDispatchNodeGetMemoryParameters(virNetServerPtr server G_GNUC_UNUSED,
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
         goto cleanup;
     }
-    if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
-        goto cleanup;
+    if (args->nparams)
+        params = g_new0(virTypedParameter, args->nparams);
     nparams = args->nparams;
 
     if (virNodeGetMemoryParameters(conn, params, &nparams, flags) < 0)
@@ -5602,8 +5564,7 @@ remoteDispatchDomainMigratePrepare3Params(virNetServerPtr server G_GNUC_UNUSED,
         goto cleanup;
 
     /* Wacky world of XDR ... */
-    if (VIR_ALLOC(uri_out) < 0)
-        goto cleanup;
+    uri_out = g_new0(char *, 1);
 
     if (virDomainMigratePrepare3Params(conn, params, nparams,
                                        args->cookie_in.cookie_in_val,
@@ -5924,8 +5885,7 @@ remoteDispatchDomainCreateXMLWithFiles(virNetServerPtr server G_GNUC_UNUSED,
     if (!conn)
         goto cleanup;
 
-    if (VIR_ALLOC_N(files, msg->nfds) < 0)
-        goto cleanup;
+    files = g_new0(int, msg->nfds);
     for (i = 0; i < msg->nfds; i++) {
         if ((files[i] = virNetMessageDupFD(msg, i)) < 0)
             goto cleanup;
@@ -5969,8 +5929,7 @@ static int remoteDispatchDomainCreateWithFiles(virNetServerPtr server G_GNUC_UNU
     if (!conn)
         goto cleanup;
 
-    if (VIR_ALLOC_N(files, msg->nfds) < 0)
-        goto cleanup;
+    files = g_new0(int, msg->nfds);
     for (i = 0; i < msg->nfds; i++) {
         if ((files[i] = virNetMessageDupFD(msg, i)) < 0)
             goto cleanup;
@@ -6038,8 +5997,7 @@ remoteDispatchConnectNetworkEventRegisterAny(virNetServerPtr server G_GNUC_UNUSE
      * incomplete callback to our array, then register, then fix up
      * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on
      * success, we use 'ref' to save a copy of the pointer.  */
-    if (VIR_ALLOC(callback) < 0)
-        goto cleanup;
+    callback = g_new0(daemonClientEventCallback, 1);
     callback->client = virObjectRef(client);
     callback->program = virObjectRef(remoteProgram);
     callback->eventID = args->eventID;
@@ -6159,8 +6117,7 @@ remoteDispatchConnectStoragePoolEventRegisterAny(virNetServerPtr server G_GNUC_U
      * incomplete callback to our array, then register, then fix up
      * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on
      * success, we use 'ref' to save a copy of the pointer.  */
-    if (VIR_ALLOC(callback) < 0)
-        goto cleanup;
+    callback = g_new0(daemonClientEventCallback, 1);
     callback->client = virObjectRef(client);
     callback->program = virObjectRef(remoteProgram);
     callback->eventID = args->eventID;
@@ -6279,8 +6236,7 @@ remoteDispatchConnectNodeDeviceEventRegisterAny(virNetServerPtr server G_GNUC_UN
      * incomplete callback to our array, then register, then fix up
      * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on
      * success, we use 'ref' to save a copy of the pointer.  */
-    if (VIR_ALLOC(callback) < 0)
-        goto cleanup;
+    callback = g_new0(daemonClientEventCallback, 1);
     callback->client = virObjectRef(client);
     callback->program = virObjectRef(remoteProgram);
     callback->eventID = args->eventID;
@@ -6399,8 +6355,7 @@ remoteDispatchConnectSecretEventRegisterAny(virNetServerPtr server G_GNUC_UNUSED
      * incomplete callback to our array, then register, then fix up
      * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on
      * success, we use 'ref' to save a copy of the pointer.  */
-    if (VIR_ALLOC(callback) < 0)
-        goto cleanup;
+    callback = g_new0(daemonClientEventCallback, 1);
     callback->client = virObjectRef(client);
     callback->program = virObjectRef(remoteProgram);
     callback->eventID = args->eventID;
@@ -6514,8 +6469,7 @@ qemuDispatchConnectDomainMonitorEventRegister(virNetServerPtr server G_GNUC_UNUS
      * incomplete callback to our array, then register, then fix up
      * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on
      * success, we use 'ref' to save a copy of the pointer.  */
-    if (VIR_ALLOC(callback) < 0)
-        goto cleanup;
+    callback = g_new0(daemonClientEventCallback, 1);
     callback->client = virObjectRef(client);
     callback->program = virObjectRef(qemuProgram);
     callback->eventID = -1;
@@ -6656,9 +6610,8 @@ remoteDispatchNodeGetFreePages(virNetServerPtr server G_GNUC_UNUSED,
     }
 
     /* Allocate return buffer. */
-    if (VIR_ALLOC_N(ret->counts.counts_val,
-                    args->pages.pages_len * args->cellCount) < 0)
-        goto cleanup;
+    ret->counts.counts_val = g_new0(uint64_t,
+                                    args->pages.pages_len * args->cellCount);
 
     if ((len = virNodeGetFreePages(conn,
                                    args->pages.pages_len,
@@ -6747,9 +6700,7 @@ remoteDispatchNetworkGetDHCPLeases(virNetServerPtr server G_GNUC_UNUSED,
     }
 
     if (leases && nleases) {
-        if (VIR_ALLOC_N(ret->leases.leases_val, nleases) < 0)
-            goto cleanup;
-
+        ret->leases.leases_val = g_new0(remote_network_dhcp_lease, nleases);
         ret->leases.leases_len = nleases;
 
         for (i = 0; i < nleases; i++) {
@@ -6797,8 +6748,7 @@ remoteDispatchConnectGetAllDomainStats(virNetServerPtr server G_GNUC_UNUSED,
         goto cleanup;
 
     if (args->doms.doms_len) {
-        if (VIR_ALLOC_N(doms, args->doms.doms_len + 1) < 0)
-            goto cleanup;
+        doms = g_new0(virDomainPtr, args->doms.doms_len + 1);
 
         for (i = 0; i < args->doms.doms_len; i++) {
             if (!(doms[i] = get_nonnull_domain(conn, args->doms.doms_val[i])))
@@ -6827,9 +6777,7 @@ remoteDispatchConnectGetAllDomainStats(virNetServerPtr server G_GNUC_UNUSED,
             goto cleanup;
         }
 
-        if (VIR_ALLOC_N(ret->retStats.retStats_val, nrecords) < 0)
-            goto cleanup;
-
+        ret->retStats.retStats_val = g_new0(remote_domain_stats_record, nrecords);
         ret->retStats.retStats_len = nrecords;
 
         for (i = 0; i < nrecords; i++) {
@@ -6934,9 +6882,7 @@ remoteDispatchDomainGetFSInfo(virNetServerPtr server G_GNUC_UNUSED,
     }
 
     if (ninfo) {
-        if (VIR_ALLOC_N(ret->info.info_val, ninfo) < 0)
-            goto cleanup;
-
+        ret->info.info_val = g_new0(remote_domain_fsinfo, ninfo);
         ret->info.info_len = ninfo;
 
         for (i = 0; i < ninfo; i++) {
@@ -6956,8 +6902,7 @@ remoteDispatchDomainGetFSInfo(virNetServerPtr server G_GNUC_UNUSED,
             }
 
             if (ndisk > 0) {
-                if (VIR_ALLOC_N(dst->dev_aliases.dev_aliases_val, ndisk) < 0)
-                    goto cleanup;
+                dst->dev_aliases.dev_aliases_val = g_new0(char *, ndisk);
 
                 for (j = 0; j < ndisk; j++)
                     dst->dev_aliases.dev_aliases_val[j] = g_strdup(info[i]->devAlias[j]);
@@ -7019,9 +6964,7 @@ remoteSerializeDomainInterface(virDomainInterfacePtr *ifaces,
         return -1;
     }
 
-    if (VIR_ALLOC_N(ret->ifaces.ifaces_val, ifaces_count) < 0)
-        return -1;
-
+    ret->ifaces.ifaces_val = g_new0(remote_domain_interface, ifaces_count);
     ret->ifaces.ifaces_len = ifaces_count;
 
     for (i = 0; i < ifaces_count; i++) {
@@ -7031,8 +6974,7 @@ remoteSerializeDomainInterface(virDomainInterfacePtr *ifaces,
         iface_ret->name = g_strdup(iface->name);
 
         if (iface->hwaddr) {
-            if (VIR_ALLOC(iface_ret->hwaddr) < 0)
-                goto cleanup;
+            iface_ret->hwaddr = g_new0(char *, 1);
             *iface_ret->hwaddr = g_strdup(iface->hwaddr);
         }
 
@@ -7043,10 +6985,7 @@ remoteSerializeDomainInterface(virDomainInterfacePtr *ifaces,
             goto cleanup;
         }
 
-        if (VIR_ALLOC_N(iface_ret->addrs.addrs_val,
-                        iface->naddrs) < 0)
-            goto cleanup;
-
+        iface_ret->addrs.addrs_val = g_new0(remote_domain_ip_addr, iface->naddrs);
         iface_ret->addrs.addrs_len = iface->naddrs;
 
         for (j = 0; j < iface->naddrs; j++) {
@@ -7362,8 +7301,7 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors,
     remote_domain_disk_error *val = NULL;
     size_t i = 0;
 
-    if (VIR_ALLOC_N(val, nerrors) < 0)
-        goto error;
+    val = g_new0(remote_domain_disk_error, nerrors);
 
     for (i = 0; i < nerrors; i++) {
         val[i].disk = g_strdup(errors[i].disk);
@@ -7374,15 +7312,6 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors,
     *ret_errors_val = val;
 
     return 0;
-
- error:
-    if (val) {
-        size_t j;
-        for (j = 0; j < i; j++)
-            VIR_FREE(val[j].disk);
-        VIR_FREE(val);
-    }
-    return -1;
 }
 
 static int
diff --git a/src/remote/remote_daemon_stream.c b/src/remote/remote_daemon_stream.c
index 9a62189cd6..b4a3cb6741 100644
--- a/src/remote/remote_daemon_stream.c
+++ b/src/remote/remote_daemon_stream.c
@@ -362,8 +362,7 @@ daemonCreateClientStream(virNetServerClientPtr client,
     VIR_DEBUG("client=%p, proc=%d, serial=%u, st=%p",
               client, header->proc, header->serial, st);
 
-    if (VIR_ALLOC(stream) < 0)
-        return NULL;
+    stream = g_new0(daemonClientStream, 1);
 
     stream->refs = 1;
     stream->priv = priv;
@@ -853,8 +852,7 @@ daemonStreamHandleRead(virNetServerClientPtr client,
 
     memset(&rerr, 0, sizeof(rerr));
 
-    if (VIR_ALLOC_N(buffer, bufferLen) < 0)
-        return -1;
+    buffer = g_new0(char, bufferLen);
 
     if (!(msg = virNetMessageNew(false)))
         goto cleanup;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 6e0c04f168..49769ac04d 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1207,8 +1207,7 @@ static struct private_data *
 remoteAllocPrivateData(void)
 {
     struct private_data *priv;
-    if (VIR_ALLOC(priv) < 0)
-        return NULL;
+    priv = g_new0(struct private_data, 1);
 
     if (virMutexInit(&priv->lock) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -2271,18 +2270,15 @@ remoteDomainGetIOThreadInfo(virDomainPtr dom,
             goto cleanup;
         }
 
-        if (VIR_ALLOC_N(info_ret, ret.info.info_len) < 0)
-            goto cleanup;
+        info_ret = g_new0(virDomainIOThreadInfoPtr, ret.info.info_len);
 
         for (i = 0; i < ret.info.info_len; i++) {
             src = &ret.info.info_val[i];
 
-            if (VIR_ALLOC(info_ret[i]) < 0)
-                goto cleanup;
+            info_ret[i] = g_new0(virDomainIOThreadInfo, 1);
 
             info_ret[i]->iothread_id = src->iothread_id;
-            if (VIR_ALLOC_N(info_ret[i]->cpumap, src->cpumap.cpumap_len) < 0)
-                goto cleanup;
+            info_ret[i]->cpumap = g_new0(unsigned char, src->cpumap.cpumap_len);
             memcpy(info_ret[i]->cpumap, src->cpumap.cpumap_val,
                    src->cpumap.cpumap_len);
             info_ret[i]->cpumaplen = src->cpumap.cpumap_len;
@@ -2367,8 +2363,7 @@ remoteDomainGetSecurityLabelList(virDomainPtr domain, virSecurityLabelPtr* secla
         goto done;
     }
 
-    if (VIR_ALLOC_N(*seclabels, ret.labels.labels_len) < 0)
-        goto cleanup;
+    *seclabels = g_new0(virSecurityLabel, ret.labels.labels_len);
 
     for (i = 0; i < ret.labels.labels_len; i++) {
         remote_domain_get_security_label_ret *cur = &ret.labels.labels_val[i];
@@ -3766,8 +3761,7 @@ static sasl_callback_t *remoteAuthMakeCallbacks(int *credtype, int ncredtype)
     sasl_callback_t *cbs;
     size_t i;
     int n;
-    if (VIR_ALLOC_N(cbs, ncredtype+1) < 0)
-        return NULL;
+    cbs = g_new0(sasl_callback_t, ncredtype + 1);
 
     for (i = 0, n = 0; i < ncredtype; i++) {
         int id = remoteAuthCredVir2SASL(credtype[i]);
@@ -3804,8 +3798,7 @@ static int remoteAuthMakeCredentials(sasl_interact_t *interact,
         (*ncred)++;
     }
 
-    if (VIR_ALLOC_N(*cred, *ncred) < 0)
-        return -1;
+    *cred = g_new0(virConnectCredential, *ncred);
 
     for (ninteract = 0, *ncred = 0; interact[ninteract].id != 0; ninteract++) {
         if (interact[ninteract].result)
@@ -4665,22 +4658,18 @@ remoteDomainBuildEventGraphicsHelper(virConnectPtr conn,
     if (!dom)
         return;
 
-    if (VIR_ALLOC(localAddr) < 0)
-        goto error;
+    localAddr = g_new0(virDomainEventGraphicsAddress, 1);
     localAddr->family = msg->local.family;
     localAddr->service = g_strdup(msg->local.service);
     localAddr->node = g_strdup(msg->local.node);
 
-    if (VIR_ALLOC(remoteAddr) < 0)
-        goto error;
+    remoteAddr = g_new0(virDomainEventGraphicsAddress, 1);
     remoteAddr->family = msg->remote.family;
     remoteAddr->service = g_strdup(msg->remote.service);
     remoteAddr->node = g_strdup(msg->remote.node);
 
-    if (VIR_ALLOC(subject) < 0)
-        goto error;
-    if (VIR_ALLOC_N(subject->identities, msg->subject.subject_len) < 0)
-        goto error;
+    subject = g_new0(virDomainEventGraphicsSubject, 1);
+    subject->identities = g_new0(virDomainEventGraphicsSubjectIdentity, msg->subject.subject_len);
     subject->nidentity = msg->subject.subject_len;
     for (i = 0; i < subject->nidentity; i++) {
         subject->identities[i].type = g_strdup(msg->subject.subject_val[i].type);
@@ -4698,28 +4687,6 @@ remoteDomainBuildEventGraphicsHelper(virConnectPtr conn,
 
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
     return;
-
- error:
-    if (localAddr) {
-        VIR_FREE(localAddr->service);
-        VIR_FREE(localAddr->node);
-        VIR_FREE(localAddr);
-    }
-    if (remoteAddr) {
-        VIR_FREE(remoteAddr->service);
-        VIR_FREE(remoteAddr->node);
-        VIR_FREE(remoteAddr);
-    }
-    if (subject) {
-        for (i = 0; i < subject->nidentity; i++) {
-            VIR_FREE(subject->identities[i].type);
-            VIR_FREE(subject->identities[i].name);
-        }
-        VIR_FREE(subject->identities);
-        VIR_FREE(subject);
-    }
-    virObjectUnref(dom);
-    return;
 }
 static void
 remoteDomainBuildEventGraphics(virNetClientProgramPtr prog G_GNUC_UNUSED,
@@ -5640,8 +5607,7 @@ remoteStreamEventAddCallback(virStreamPtr st,
     int ret = -1;
     struct remoteStreamCallbackData *cbdata;
 
-    if (VIR_ALLOC(cbdata) < 0)
-        return -1;
+    cbdata = g_new0(struct remoteStreamCallbackData, 1);
     cbdata->cb = cb;
     cbdata->opaque = opaque;
     cbdata->ff = ff;
@@ -6304,8 +6270,7 @@ remoteConnectGetCPUModelNames(virConnectPtr conn,
     }
 
     if (models) {
-        if (VIR_ALLOC_N(retmodels, ret.models.models_len + 1) < 0)
-            goto cleanup;
+        retmodels = g_new0(char *, ret.models.models_len + 1);
 
         for (i = 0; i < ret.models.models_len; i++) {
             retmodels[i] = ret.models.models_val[i];
@@ -6738,8 +6703,7 @@ remoteNodeGetCPUMap(virConnectPtr conn,
         goto cleanup;
 
     if (cpumap) {
-        if (VIR_ALLOC_N(*cpumap, ret.cpumap.cpumap_len) < 0)
-            goto cleanup;
+        *cpumap = g_new0(unsigned char, ret.cpumap.cpumap_len);
         memcpy(*cpumap, ret.cpumap.cpumap_val, ret.cpumap.cpumap_len);
     }
 
@@ -7467,13 +7431,11 @@ remoteNetworkGetDHCPLeases(virNetworkPtr net,
     }
 
     if (leases) {
-        if (ret.leases.leases_len &&
-            VIR_ALLOC_N(leases_ret, ret.leases.leases_len + 1) < 0)
-            goto cleanup;
+        if (ret.leases.leases_len)
+            leases_ret = g_new0(virNetworkDHCPLeasePtr, ret.leases.leases_len + 1);
 
         for (i = 0; i < ret.leases.leases_len; i++) {
-            if (VIR_ALLOC(leases_ret[i]) < 0)
-                goto cleanup;
+            leases_ret[i] = g_new0(virNetworkDHCPLease, 1);
 
             if (remoteSerializeDHCPLease(leases_ret[i], &ret.leases.leases_val[i]) < 0)
                 goto cleanup;
@@ -7519,8 +7481,7 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
     memset(&args, 0, sizeof(args));
 
     if (ndoms) {
-        if (VIR_ALLOC_N(args.doms.doms_val, ndoms) < 0)
-            goto cleanup;
+        args.doms.doms_val = g_new0(remote_nonnull_domain, ndoms);
 
         for (i = 0; i < ndoms; i++)
             make_nonnull_domain(args.doms.doms_val + i, doms[i]);
@@ -7550,14 +7511,12 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
 
     *retStats = NULL;
 
-    if (VIR_ALLOC_N(tmpret, ret.retStats.retStats_len + 1) < 0)
-        goto cleanup;
+    tmpret = g_new0(virDomainStatsRecordPtr, ret.retStats.retStats_len + 1);
 
     for (i = 0; i < ret.retStats.retStats_len; i++) {
         remote_domain_stats_record *rec = ret.retStats.retStats_val + i;
 
-        if (VIR_ALLOC(elem) < 0)
-            goto cleanup;
+        elem = g_new0(virDomainStatsRecord, 1);
 
         if (!(elem->dom = get_nonnull_domain(conn, rec->dom)))
             goto cleanup;
@@ -7676,14 +7635,13 @@ remoteDomainGetFSInfo(virDomainPtr dom,
             goto cleanup;
         }
 
-        if (VIR_ALLOC_N(info_ret, ret.info.info_len) < 0)
+        info_ret = g_new0(virDomainFSInfoPtr, ret.info.info_len);
             goto cleanup;
 
         for (i = 0; i < ret.info.info_len; i++) {
             src = &ret.info.info_val[i];
 
-            if (VIR_ALLOC(info_ret[i]) < 0)
-                goto cleanup;
+            info_ret[i] = g_new0(virDomainFSInfo, 1);
 
             info_ret[i]->mountpoint = g_strdup(src->mountpoint);
 
@@ -7693,9 +7651,8 @@ remoteDomainGetFSInfo(virDomainPtr dom,
 
             len = src->dev_aliases.dev_aliases_len;
             info_ret[i]->ndevAlias = len;
-            if (len &&
-                VIR_ALLOC_N(info_ret[i]->devAlias, len) < 0)
-                goto cleanup;
+            if (len)
+                info_ret[i]->devAlias = g_new0(char *, len);
 
             for (j = 0; j < len; j++)
                 info_ret[i]->devAlias[j] = g_strdup(src->dev_aliases.dev_aliases_val[j]);
@@ -7760,16 +7717,14 @@ remoteDomainInterfaceAddresses(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (ret.ifaces.ifaces_len &&
-        VIR_ALLOC_N(ifaces_ret, ret.ifaces.ifaces_len) < 0)
-        goto cleanup;
+    if (ret.ifaces.ifaces_len)
+        ifaces_ret = g_new0(virDomainInterfacePtr, ret.ifaces.ifaces_len);
 
     for (i = 0; i < ret.ifaces.ifaces_len; i++) {
         virDomainInterfacePtr iface;
         remote_domain_interface *iface_ret = &(ret.ifaces.ifaces_val[i]);
 
-        if (VIR_ALLOC(ifaces_ret[i]) < 0)
-            goto cleanup;
+        ifaces_ret[i] = g_new0(virDomainInterface, 1);
 
         iface = ifaces_ret[i];
 
@@ -7788,8 +7743,7 @@ remoteDomainInterfaceAddresses(virDomainPtr dom,
         iface->naddrs = iface_ret->addrs.addrs_len;
 
         if (iface->naddrs) {
-            if (VIR_ALLOC_N(iface->addrs, iface->naddrs) < 0)
-                goto cleanup;
+            iface->addrs = g_new0(virDomainIPAddress, iface->naddrs);
 
            for (j = 0; j < iface->naddrs; j++) {
                 virDomainIPAddressPtr ip_addr = &(iface->addrs[j]);
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux