Adapt to VIR_ALLOC and virAsprintf in src/remote/*

This commit is contained in:
Michal Privoznik 2013-07-04 12:14:34 +02:00
parent e987a30dfa
commit 7be0e3c9d8

View File

@ -495,7 +495,7 @@ doRemoteOpen(virConnectPtr conn,
/* Remote server defaults to "localhost" if not specified. */ /* Remote server defaults to "localhost" if not specified. */
if (conn->uri && conn->uri->port != 0) { if (conn->uri && conn->uri->port != 0) {
if (virAsprintf(&port, "%d", conn->uri->port) < 0) if (virAsprintf(&port, "%d", conn->uri->port) < 0)
goto no_memory; goto failed;
} else if (transport == trans_tls) { } else if (transport == trans_tls) {
if (VIR_STRDUP(port, LIBVIRTD_TLS_PORT) < 0) if (VIR_STRDUP(port, LIBVIRTD_TLS_PORT) < 0)
goto failed; goto failed;
@ -677,7 +677,7 @@ doRemoteOpen(virConnectPtr conn,
if (virAsprintf(&sockname, "%s/" LIBVIRTD_USER_UNIX_SOCKET, userdir) < 0) { if (virAsprintf(&sockname, "%s/" LIBVIRTD_USER_UNIX_SOCKET, userdir) < 0) {
VIR_FREE(userdir); VIR_FREE(userdir);
goto no_memory; goto failed;
} }
VIR_FREE(userdir); VIR_FREE(userdir);
} else { } else {
@ -878,9 +878,6 @@ doRemoteOpen(virConnectPtr conn,
return retcode; return retcode;
no_memory:
virReportOOMError();
failed: failed:
virObjectUnref(priv->remoteProgram); virObjectUnref(priv->remoteProgram);
virObjectUnref(priv->lxcProgram); virObjectUnref(priv->lxcProgram);
@ -899,10 +896,8 @@ static struct private_data *
remoteAllocPrivateData(void) remoteAllocPrivateData(void)
{ {
struct private_data *priv; struct private_data *priv;
if (VIR_ALLOC(priv) < 0) { if (VIR_ALLOC(priv) < 0)
virReportOOMError();
return NULL; return NULL;
}
if (virMutexInit(&priv->lock) < 0) { if (virMutexInit(&priv->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -1429,18 +1424,14 @@ remoteConnectListAllDomains(virConnectPtr conn,
goto done; goto done;
if (domains) { if (domains) {
if (VIR_ALLOC_N(doms, ret.domains.domains_len + 1) < 0) { if (VIR_ALLOC_N(doms, ret.domains.domains_len + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < ret.domains.domains_len; i++) { for (i = 0; i < ret.domains.domains_len; i++) {
doms[i] = get_nonnull_domain(conn, ret.domains.domains_val[i]); doms[i] = get_nonnull_domain(conn, ret.domains.domains_val[i]);
if (!doms[i]) { if (!doms[i])
virReportOOMError();
goto cleanup; goto cleanup;
} }
}
*domains = doms; *domains = doms;
doms = NULL; doms = NULL;
} }
@ -1493,10 +1484,8 @@ remoteSerializeTypedParameters(virTypedParameterPtr params,
remote_typed_param *val; remote_typed_param *val;
*args_params_len = nparams; *args_params_len = nparams;
if (VIR_ALLOC_N(val, nparams) < 0) { if (VIR_ALLOC_N(val, nparams) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < nparams; ++i) { for (i = 0; i < nparams; ++i) {
/* call() will free this: */ /* call() will free this: */
@ -1563,11 +1552,9 @@ remoteDeserializeTypedParameters(remote_typed_param *ret_params_val,
goto cleanup; goto cleanup;
} }
} else { } else {
if (VIR_ALLOC_N(*params, ret_params_len) < 0) { if (VIR_ALLOC_N(*params, ret_params_len) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
} }
}
*nparams = ret_params_len; *nparams = ret_params_len;
/* Deserialise the result. */ /* Deserialise the result. */
@ -2850,18 +2837,14 @@ remoteConnectListAllNetworks(virConnectPtr conn,
goto done; goto done;
if (nets) { if (nets) {
if (VIR_ALLOC_N(tmp_nets, ret.nets.nets_len + 1) < 0) { if (VIR_ALLOC_N(tmp_nets, ret.nets.nets_len + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < ret.nets.nets_len; i++) { for (i = 0; i < ret.nets.nets_len; i++) {
tmp_nets[i] = get_nonnull_network(conn, ret.nets.nets_val[i]); tmp_nets[i] = get_nonnull_network(conn, ret.nets.nets_val[i]);
if (!tmp_nets[i]) { if (!tmp_nets[i])
virReportOOMError();
goto cleanup; goto cleanup;
} }
}
*nets = tmp_nets; *nets = tmp_nets;
tmp_nets = NULL; tmp_nets = NULL;
} }
@ -2913,18 +2896,14 @@ remoteConnectListAllInterfaces(virConnectPtr conn,
goto done; goto done;
if (ifaces) { if (ifaces) {
if (VIR_ALLOC_N(tmp_ifaces, ret.ifaces.ifaces_len + 1) < 0) { if (VIR_ALLOC_N(tmp_ifaces, ret.ifaces.ifaces_len + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < ret.ifaces.ifaces_len; i++) { for (i = 0; i < ret.ifaces.ifaces_len; i++) {
tmp_ifaces[i] = get_nonnull_interface(conn, ret.ifaces.ifaces_val[i]); tmp_ifaces[i] = get_nonnull_interface(conn, ret.ifaces.ifaces_val[i]);
if (!tmp_ifaces[i]) { if (!tmp_ifaces[i])
virReportOOMError();
goto cleanup; goto cleanup;
} }
}
*ifaces = tmp_ifaces; *ifaces = tmp_ifaces;
tmp_ifaces = NULL; tmp_ifaces = NULL;
} }
@ -2976,18 +2955,14 @@ remoteConnectListAllNodeDevices(virConnectPtr conn,
goto done; goto done;
if (devices) { if (devices) {
if (VIR_ALLOC_N(tmp_devices, ret.devices.devices_len + 1) < 0) { if (VIR_ALLOC_N(tmp_devices, ret.devices.devices_len + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < ret.devices.devices_len; i++) { for (i = 0; i < ret.devices.devices_len; i++) {
tmp_devices[i] = get_nonnull_node_device(conn, ret.devices.devices_val[i]); tmp_devices[i] = get_nonnull_node_device(conn, ret.devices.devices_val[i]);
if (!tmp_devices[i]) { if (!tmp_devices[i])
virReportOOMError();
goto cleanup; goto cleanup;
} }
}
*devices = tmp_devices; *devices = tmp_devices;
tmp_devices = NULL; tmp_devices = NULL;
} }
@ -3039,18 +3014,14 @@ remoteConnectListAllNWFilters(virConnectPtr conn,
goto done; goto done;
if (filters) { if (filters) {
if (VIR_ALLOC_N(tmp_filters, ret.filters.filters_len + 1) < 0) { if (VIR_ALLOC_N(tmp_filters, ret.filters.filters_len + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < ret.filters.filters_len; i++) { for (i = 0; i < ret.filters.filters_len; i++) {
tmp_filters[i] = get_nonnull_nwfilter(conn, ret.filters.filters_val[i]); tmp_filters[i] = get_nonnull_nwfilter(conn, ret.filters.filters_val[i]);
if (!tmp_filters[i]) { if (!tmp_filters[i])
virReportOOMError();
goto cleanup; goto cleanup;
} }
}
*filters = tmp_filters; *filters = tmp_filters;
tmp_filters = NULL; tmp_filters = NULL;
} }
@ -3102,18 +3073,14 @@ remoteConnectListAllSecrets(virConnectPtr conn,
goto done; goto done;
if (secrets) { if (secrets) {
if (VIR_ALLOC_N(tmp_secrets, ret.secrets.secrets_len + 1) < 0) { if (VIR_ALLOC_N(tmp_secrets, ret.secrets.secrets_len + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < ret.secrets.secrets_len; i++) { for (i = 0; i < ret.secrets.secrets_len; i++) {
tmp_secrets[i] = get_nonnull_secret(conn, ret.secrets.secrets_val[i]); tmp_secrets[i] = get_nonnull_secret(conn, ret.secrets.secrets_val[i]);
if (!tmp_secrets[i]) { if (!tmp_secrets[i])
virReportOOMError();
goto cleanup; goto cleanup;
} }
}
*secrets = tmp_secrets; *secrets = tmp_secrets;
tmp_secrets = NULL; tmp_secrets = NULL;
} }
@ -3303,18 +3270,14 @@ remoteConnectListAllStoragePools(virConnectPtr conn,
goto done; goto done;
if (pools) { if (pools) {
if (VIR_ALLOC_N(tmp_pools, ret.pools.pools_len + 1) < 0) { if (VIR_ALLOC_N(tmp_pools, ret.pools.pools_len + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < ret.pools.pools_len; i++) { for (i = 0; i < ret.pools.pools_len; i++) {
tmp_pools[i] = get_nonnull_storage_pool(conn, ret.pools.pools_val[i]); tmp_pools[i] = get_nonnull_storage_pool(conn, ret.pools.pools_val[i]);
if (!tmp_pools[i]) { if (!tmp_pools[i])
virReportOOMError();
goto cleanup; goto cleanup;
} }
}
*pools = tmp_pools; *pools = tmp_pools;
tmp_pools = NULL; tmp_pools = NULL;
} }
@ -3367,18 +3330,14 @@ remoteStoragePoolListAllVolumes(virStoragePoolPtr pool,
goto done; goto done;
if (vols) { if (vols) {
if (VIR_ALLOC_N(tmp_vols, ret.vols.vols_len + 1) < 0) { if (VIR_ALLOC_N(tmp_vols, ret.vols.vols_len + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < ret.vols.vols_len; i++) { for (i = 0; i < ret.vols.vols_len; i++) {
tmp_vols[i] = get_nonnull_storage_vol(pool->conn, ret.vols.vols_val[i]); tmp_vols[i] = get_nonnull_storage_vol(pool->conn, ret.vols.vols_val[i]);
if (!tmp_vols[i]) { if (!tmp_vols[i])
virReportOOMError();
goto cleanup; goto cleanup;
} }
}
*vols = tmp_vols; *vols = tmp_vols;
tmp_vols = NULL; tmp_vols = NULL;
} }
@ -4881,10 +4840,8 @@ remoteStreamEventAddCallback(virStreamPtr st,
int ret = -1; int ret = -1;
struct remoteStreamCallbackData *cbdata; struct remoteStreamCallbackData *cbdata;
if (VIR_ALLOC(cbdata) < 0) { if (VIR_ALLOC(cbdata) < 0)
virReportOOMError();
return -1; return -1;
}
cbdata->cb = cb; cbdata->cb = cb;
cbdata->opaque = opaque; cbdata->opaque = opaque;
cbdata->ff = ff; cbdata->ff = ff;
@ -5778,17 +5735,13 @@ remoteDomainListAllSnapshots(virDomainPtr dom,
goto done; goto done;
if (snapshots) { if (snapshots) {
if (VIR_ALLOC_N(snaps, ret.snapshots.snapshots_len + 1) < 0) { if (VIR_ALLOC_N(snaps, ret.snapshots.snapshots_len + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < ret.snapshots.snapshots_len; i++) { for (i = 0; i < ret.snapshots.snapshots_len; i++) {
snaps[i] = get_nonnull_domain_snapshot(dom, ret.snapshots.snapshots_val[i]); snaps[i] = get_nonnull_domain_snapshot(dom, ret.snapshots.snapshots_val[i]);
if (!snaps[i]) { if (!snaps[i])
virReportOOMError();
goto cleanup; goto cleanup;
} }
}
*snapshots = snaps; *snapshots = snaps;
snaps = NULL; snaps = NULL;
} }
@ -5841,17 +5794,13 @@ remoteDomainSnapshotListAllChildren(virDomainSnapshotPtr parent,
goto done; goto done;
if (snapshots) { if (snapshots) {
if (VIR_ALLOC_N(snaps, ret.snapshots.snapshots_len + 1) < 0) { if (VIR_ALLOC_N(snaps, ret.snapshots.snapshots_len + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < ret.snapshots.snapshots_len; i++) { for (i = 0; i < ret.snapshots.snapshots_len; i++) {
snaps[i] = get_nonnull_domain_snapshot(parent->domain, ret.snapshots.snapshots_val[i]); snaps[i] = get_nonnull_domain_snapshot(parent->domain, ret.snapshots.snapshots_val[i]);
if (!snaps[i]) { if (!snaps[i])
virReportOOMError();
goto cleanup; goto cleanup;
} }
}
*snapshots = snaps; *snapshots = snaps;
snaps = NULL; snaps = NULL;
} }
@ -5950,10 +5899,8 @@ remoteNodeGetCPUMap(virConnectPtr conn,
goto cleanup; goto cleanup;
if (cpumap) { if (cpumap) {
if (VIR_ALLOC_N(*cpumap, ret.cpumap.cpumap_len) < 0) { if (VIR_ALLOC_N(*cpumap, ret.cpumap.cpumap_len) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
memcpy(*cpumap, ret.cpumap.cpumap_val, ret.cpumap.cpumap_len); memcpy(*cpumap, ret.cpumap.cpumap_val, ret.cpumap.cpumap_len);
} }