1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

Adapt to VIR_STRDUP and VIR_STRNDUP in daemon/*

This commit is contained in:
Michal Privoznik 2013-05-03 14:39:39 +02:00
parent c3abb5c459
commit a54434f4ba
3 changed files with 91 additions and 148 deletions

View File

@ -59,15 +59,11 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg,
key); key);
return -1; return -1;
} }
list[0] = strdup(p->str); if (VIR_STRDUP(list[0], p->str) < 0) {
list[1] = NULL;
if (list[0] == NULL) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("failed to allocate memory for %s config list value"),
key);
VIR_FREE(list); VIR_FREE(list);
return -1; return -1;
} }
list[1] = NULL;
break; break;
case VIR_CONF_LIST: { case VIR_CONF_LIST: {
@ -90,15 +86,11 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg,
VIR_FREE(list); VIR_FREE(list);
return -1; return -1;
} }
list[i] = strdup(pp->str); if (VIR_STRDUP(list[i], pp->str) < 0) {
if (list[i] == NULL) {
int j; int j;
for (j = 0 ; j < i ; j++) for (j = 0 ; j < i ; j++)
VIR_FREE(list[j]); VIR_FREE(list[j]);
VIR_FREE(list); VIR_FREE(list);
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("failed to allocate memory for %s config list value"),
key);
return -1; return -1;
} }
@ -136,8 +128,8 @@ checkType(virConfValuePtr p, const char *filename,
} }
/* If there is no config data for the key, #var_name, then do nothing. /* If there is no config data for the key, #var_name, then do nothing.
If there is valid data of type VIR_CONF_STRING, and strdup succeeds, If there is valid data of type VIR_CONF_STRING, and VIR_STRDUP succeeds,
store the result in var_name. Otherwise, (i.e. invalid type, or strdup store the result in var_name. Otherwise, (i.e. invalid type, or VIR_STRDUP
failure), give a diagnostic and "goto" the cleanup-and-fail label. */ failure), give a diagnostic and "goto" the cleanup-and-fail label. */
#define GET_CONF_STR(conf, filename, var_name) \ #define GET_CONF_STR(conf, filename, var_name) \
do { \ do { \
@ -146,10 +138,8 @@ checkType(virConfValuePtr p, const char *filename,
if (checkType(p, filename, #var_name, VIR_CONF_STRING) < 0) \ if (checkType(p, filename, #var_name, VIR_CONF_STRING) < 0) \
goto error; \ goto error; \
VIR_FREE(data->var_name); \ VIR_FREE(data->var_name); \
if (!(data->var_name = strdup(p->str))) { \ if (VIR_STRDUP(data->var_name, p->str) < 0) \
virReportOOMError(); \
goto error; \ goto error; \
} \
} \ } \
} while (0) } while (0)
@ -200,8 +190,8 @@ int
daemonConfigFilePath(bool privileged, char **configfile) daemonConfigFilePath(bool privileged, char **configfile)
{ {
if (privileged) { if (privileged) {
if (!(*configfile = strdup(SYSCONFDIR "/libvirt/libvirtd.conf"))) if (VIR_STRDUP(*configfile, SYSCONFDIR "/libvirt/libvirtd.conf") < 0)
goto no_memory; goto error;
} else { } else {
char *configdir = NULL; char *configdir = NULL;
@ -238,10 +228,9 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED)
data->listen_tls = 1; data->listen_tls = 1;
data->listen_tcp = 0; data->listen_tcp = 0;
if (!(data->tls_port = strdup(LIBVIRTD_TLS_PORT))) if (VIR_STRDUP(data->tls_port, LIBVIRTD_TLS_PORT) < 0 ||
goto no_memory; VIR_STRDUP(data->tcp_port, LIBVIRTD_TCP_PORT) < 0)
if (!(data->tcp_port = strdup(LIBVIRTD_TCP_PORT))) goto error;
goto no_memory;
/* Only default to PolicyKit if running as root */ /* Only default to PolicyKit if running as root */
#if WITH_POLKIT #if WITH_POLKIT
@ -256,14 +245,10 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED)
} }
#endif #endif
if (data->auth_unix_rw == REMOTE_AUTH_POLKIT) if (VIR_STRDUP(data->unix_sock_rw_perms,
data->unix_sock_rw_perms = strdup("0777"); /* Allow world */ data->auth_unix_rw == REMOTE_AUTH_POLKIT ? "0777" : "0700") < 0 ||
else VIR_STRDUP(data->unix_sock_ro_perms, "0777") < 0)
data->unix_sock_rw_perms = strdup("0700"); /* Allow user only */ goto error;
data->unix_sock_ro_perms = strdup("0777"); /* Always allow world */
if (!data->unix_sock_ro_perms ||
!data->unix_sock_rw_perms)
goto no_memory;
#if WITH_SASL #if WITH_SASL
data->auth_tcp = REMOTE_AUTH_SASL; data->auth_tcp = REMOTE_AUTH_SASL;
@ -315,6 +300,7 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED)
no_memory: no_memory:
virReportOOMError(); virReportOOMError();
error:
daemonConfigFree(data); daemonConfigFree(data);
return NULL; return NULL;
} }
@ -382,10 +368,8 @@ daemonConfigLoadOptions(struct daemonConfig *data,
*/ */
if (data->auth_unix_rw == REMOTE_AUTH_POLKIT) { if (data->auth_unix_rw == REMOTE_AUTH_POLKIT) {
VIR_FREE(data->unix_sock_rw_perms); VIR_FREE(data->unix_sock_rw_perms);
if (!(data->unix_sock_rw_perms = strdup("0777"))) { if (VIR_STRDUP(data->unix_sock_rw_perms, "0777") < 0)
virReportOOMError();
goto error; goto error;
}
} }
#endif #endif
if (remoteConfigGetAuth(conf, "auth_unix_ro", &data->auth_unix_ro, filename) < 0) if (remoteConfigGetAuth(conf, "auth_unix_ro", &data->auth_unix_ro, filename) < 0)

View File

@ -241,8 +241,8 @@ daemonPidFilePath(bool privileged,
char **pidfile) char **pidfile)
{ {
if (privileged) { if (privileged) {
if (!(*pidfile = strdup(LOCALSTATEDIR "/run/libvirtd.pid"))) if (VIR_STRDUP(*pidfile, LOCALSTATEDIR "/run/libvirtd.pid") < 0)
goto no_memory; goto error;
} else { } else {
char *rundir = NULL; char *rundir = NULL;
mode_t old_umask; mode_t old_umask;
@ -287,10 +287,9 @@ daemonUnixSocketPaths(struct daemonConfig *config,
goto no_memory; goto no_memory;
} else { } else {
if (privileged) { if (privileged) {
if (!(*sockfile = strdup(LOCALSTATEDIR "/run/libvirt/libvirt-sock"))) if (VIR_STRDUP(*sockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock") < 0 ||
goto no_memory; VIR_STRDUP(*rosockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro") < 0)
if (!(*rosockfile = strdup(LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro"))) goto error;
goto no_memory;
} else { } else {
char *rundir = NULL; char *rundir = NULL;
mode_t old_umask; mode_t old_umask;
@ -961,7 +960,8 @@ static int migrateProfile(void)
config_home = getenv("XDG_CONFIG_HOME"); config_home = getenv("XDG_CONFIG_HOME");
if (config_home && config_home[0] != '\0') { if (config_home && config_home[0] != '\0') {
xdg_dir = strdup(config_home); if (VIR_STRDUP(xdg_dir, config_home) < 0)
goto cleanup;
} else { } else {
if (virAsprintf(&xdg_dir, "%s/.config", home) < 0) { if (virAsprintf(&xdg_dir, "%s/.config", home) < 0) {
goto cleanup; goto cleanup;
@ -1172,7 +1172,7 @@ int main(int argc, char **argv) {
case 'p': case 'p':
VIR_FREE(pid_file); VIR_FREE(pid_file);
if (!(pid_file = strdup(optarg))) { if (VIR_STRDUP_QUIET(pid_file, optarg) < 0) {
VIR_ERROR(_("Can't allocate memory")); VIR_ERROR(_("Can't allocate memory"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -1180,7 +1180,7 @@ int main(int argc, char **argv) {
case 'f': case 'f':
VIR_FREE(remote_config_file); VIR_FREE(remote_config_file);
if (!(remote_config_file = strdup(optarg))) { if (VIR_STRDUP_QUIET(remote_config_file, optarg) < 0) {
VIR_ERROR(_("Can't allocate memory")); VIR_ERROR(_("Can't allocate memory"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -1287,7 +1287,10 @@ int main(int argc, char **argv) {
/* Ensure the rundir exists (on tmpfs on some systems) */ /* Ensure the rundir exists (on tmpfs on some systems) */
if (privileged) { if (privileged) {
run_dir = strdup(LOCALSTATEDIR "/run/libvirt"); if (VIR_STRDUP_QUIET(run_dir, LOCALSTATEDIR "/run/libvirt") < 0) {
VIR_ERROR(_("Can't allocate memory"));
goto cleanup;
}
} else { } else {
run_dir = virGetUserRuntimeDirectory(); run_dir = virGetUserRuntimeDirectory();
@ -1296,11 +1299,6 @@ int main(int argc, char **argv) {
goto cleanup; goto cleanup;
} }
} }
if (!run_dir) {
virReportOOMError();
goto cleanup;
}
if (privileged) if (privileged)
old_umask = umask(022); old_umask = umask(022);
else else

View File

@ -234,12 +234,9 @@ static int remoteRelayDomainEventIOError(virConnectPtr conn ATTRIBUTE_UNUSED,
/* build return data */ /* build return data */
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
data.srcPath = strdup(srcPath); if (VIR_STRDUP(data.srcPath, srcPath) < 0 ||
if (data.srcPath == NULL) VIR_STRDUP(data.devAlias, devAlias) < 0)
goto mem_error; goto error;
data.devAlias = strdup(devAlias);
if (data.devAlias == NULL)
goto mem_error;
make_nonnull_domain(&data.dom, dom); make_nonnull_domain(&data.dom, dom);
data.action = action; data.action = action;
@ -248,8 +245,7 @@ static int remoteRelayDomainEventIOError(virConnectPtr conn ATTRIBUTE_UNUSED,
(xdrproc_t)xdr_remote_domain_event_io_error_msg, &data); (xdrproc_t)xdr_remote_domain_event_io_error_msg, &data);
return 0; return 0;
mem_error: error:
virReportOOMError();
VIR_FREE(data.srcPath); VIR_FREE(data.srcPath);
VIR_FREE(data.devAlias); VIR_FREE(data.devAlias);
return -1; return -1;
@ -275,16 +271,11 @@ static int remoteRelayDomainEventIOErrorReason(virConnectPtr conn ATTRIBUTE_UNUS
/* build return data */ /* build return data */
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
data.srcPath = strdup(srcPath); if (VIR_STRDUP(data.srcPath, srcPath) < 0 ||
if (data.srcPath == NULL) VIR_STRDUP(data.devAlias, devAlias) < 0 ||
goto mem_error; VIR_STRDUP(data.reason, reason) < 0)
data.devAlias = strdup(devAlias); goto error;
if (data.devAlias == NULL)
goto mem_error;
data.action = action; data.action = action;
data.reason = strdup(reason);
if (data.reason == NULL)
goto mem_error;
make_nonnull_domain(&data.dom, dom); make_nonnull_domain(&data.dom, dom);
@ -294,8 +285,7 @@ static int remoteRelayDomainEventIOErrorReason(virConnectPtr conn ATTRIBUTE_UNUS
return 0; return 0;
mem_error: error:
virReportOOMError();
VIR_FREE(data.srcPath); VIR_FREE(data.srcPath);
VIR_FREE(data.devAlias); VIR_FREE(data.devAlias);
VIR_FREE(data.reason); VIR_FREE(data.reason);
@ -334,35 +324,23 @@ static int remoteRelayDomainEventGraphics(virConnectPtr conn ATTRIBUTE_UNUSED,
data.phase = phase; data.phase = phase;
data.local.family = local->family; data.local.family = local->family;
data.remote.family = remote->family; data.remote.family = remote->family;
data.authScheme = strdup(authScheme); if (VIR_STRDUP(data.authScheme, authScheme) < 0 ||
if (data.authScheme == NULL) VIR_STRDUP(data.local.node, local->node) < 0 ||
goto mem_error; VIR_STRDUP(data.local.service, local->service) < 0 ||
VIR_STRDUP(data.remote.node, remote->node) < 0 ||
data.local.node = strdup(local->node); VIR_STRDUP(data.remote.service, remote->service) < 0)
if (data.local.node == NULL) goto error;
goto mem_error;
data.local.service = strdup(local->service);
if (data.local.service == NULL)
goto mem_error;
data.remote.node = strdup(remote->node);
if (data.remote.node == NULL)
goto mem_error;
data.remote.service = strdup(remote->service);
if (data.remote.service == NULL)
goto mem_error;
data.subject.subject_len = subject->nidentity; data.subject.subject_len = subject->nidentity;
if (VIR_ALLOC_N(data.subject.subject_val, data.subject.subject_len) < 0) if (VIR_ALLOC_N(data.subject.subject_val, data.subject.subject_len) < 0) {
goto mem_error; virReportOOMError();
goto error;
}
for (i = 0 ; i < data.subject.subject_len ; i++) { for (i = 0 ; i < data.subject.subject_len ; i++) {
data.subject.subject_val[i].type = strdup(subject->identities[i].type); if (VIR_STRDUP(data.subject.subject_val[i].type, subject->identities[i].type) < 0 ||
if (data.subject.subject_val[i].type == NULL) VIR_STRDUP(data.subject.subject_val[i].name, subject->identities[i].name) < 0)
goto mem_error; goto error;
data.subject.subject_val[i].name = strdup(subject->identities[i].name);
if (data.subject.subject_val[i].name == NULL)
goto mem_error;
} }
make_nonnull_domain(&data.dom, dom); make_nonnull_domain(&data.dom, dom);
@ -372,8 +350,7 @@ static int remoteRelayDomainEventGraphics(virConnectPtr conn ATTRIBUTE_UNUSED,
return 0; return 0;
mem_error: error:
virReportOOMError();
VIR_FREE(data.authScheme); VIR_FREE(data.authScheme);
VIR_FREE(data.local.node); VIR_FREE(data.local.node);
VIR_FREE(data.local.service); VIR_FREE(data.local.service);
@ -407,9 +384,8 @@ static int remoteRelayDomainEventBlockJob(virConnectPtr conn ATTRIBUTE_UNUSED,
/* build return data */ /* build return data */
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
data.path = strdup(path); if (VIR_STRDUP(data.path, path) < 0)
if (data.path == NULL) goto error;
goto mem_error;
data.type = type; data.type = type;
data.status = status; data.status = status;
make_nonnull_domain(&data.dom, dom); make_nonnull_domain(&data.dom, dom);
@ -419,9 +395,7 @@ static int remoteRelayDomainEventBlockJob(virConnectPtr conn ATTRIBUTE_UNUSED,
(xdrproc_t)xdr_remote_domain_event_block_job_msg, &data); (xdrproc_t)xdr_remote_domain_event_block_job_msg, &data);
return 0; return 0;
error:
mem_error:
virReportOOMError();
VIR_FREE(data.path); VIR_FREE(data.path);
return -1; return -1;
} }
@ -473,18 +447,18 @@ static int remoteRelayDomainEventDiskChange(virConnectPtr conn ATTRIBUTE_UNUSED,
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
if (oldSrcPath && if (oldSrcPath &&
((VIR_ALLOC(oldSrcPath_p) < 0) || ((VIR_ALLOC(oldSrcPath_p) < 0) ||
!(*oldSrcPath_p = strdup(oldSrcPath)))) VIR_STRDUP(*oldSrcPath_p, oldSrcPath) < 0))
goto mem_error; goto mem_error;
if (newSrcPath && if (newSrcPath &&
((VIR_ALLOC(newSrcPath_p) < 0) || ((VIR_ALLOC(newSrcPath_p) < 0) ||
!(*newSrcPath_p = strdup(newSrcPath)))) VIR_STRDUP(*newSrcPath_p, newSrcPath) < 0))
goto mem_error; goto mem_error;
data.oldSrcPath = oldSrcPath_p; data.oldSrcPath = oldSrcPath_p;
data.newSrcPath = newSrcPath_p; data.newSrcPath = newSrcPath_p;
if (!(data.devAlias = strdup(devAlias))) if (VIR_STRDUP(data.devAlias, devAlias) < 0)
goto mem_error; goto error;
data.reason = reason; data.reason = reason;
make_nonnull_domain(&data.dom, dom); make_nonnull_domain(&data.dom, dom);
@ -496,9 +470,10 @@ static int remoteRelayDomainEventDiskChange(virConnectPtr conn ATTRIBUTE_UNUSED,
return 0; return 0;
mem_error: mem_error:
virReportOOMError();
error:
VIR_FREE(oldSrcPath_p); VIR_FREE(oldSrcPath_p);
VIR_FREE(newSrcPath_p); VIR_FREE(newSrcPath_p);
virReportOOMError();
return -1; return -1;
} }
@ -520,10 +495,8 @@ static int remoteRelayDomainEventTrayChange(virConnectPtr conn ATTRIBUTE_UNUSED,
/* build return data */ /* build return data */
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
if (!(data.devAlias = strdup(devAlias))) { if (VIR_STRDUP(data.devAlias, devAlias) < 0)
virReportOOMError();
return -1; return -1;
}
data.reason = reason; data.reason = reason;
make_nonnull_domain(&data.dom, dom); make_nonnull_domain(&data.dom, dom);
@ -850,11 +823,8 @@ remoteSerializeTypedParameters(virTypedParameterPtr params,
} }
/* remoteDispatchClientRequest will free this: */ /* remoteDispatchClientRequest will free this: */
val[j].field = strdup(params[i].field); if (VIR_STRDUP(val[j].field, params[i].field) < 0)
if (val[j].field == NULL) {
virReportOOMError();
goto cleanup; goto cleanup;
}
val[j].value.type = params[i].type; val[j].value.type = params[i].type;
switch (params[i].type) { switch (params[i].type) {
case VIR_TYPED_PARAM_INT: case VIR_TYPED_PARAM_INT:
@ -876,12 +846,8 @@ remoteSerializeTypedParameters(virTypedParameterPtr params,
val[j].value.remote_typed_param_value_u.b = params[i].value.b; val[j].value.remote_typed_param_value_u.b = params[i].value.b;
break; break;
case VIR_TYPED_PARAM_STRING: case VIR_TYPED_PARAM_STRING:
val[j].value.remote_typed_param_value_u.s = if (VIR_STRDUP(val[j].value.remote_typed_param_value_u.s, params[i].value.s) < 0)
strdup(params[i].value.s);
if (val[j].value.remote_typed_param_value_u.s == NULL) {
virReportOOMError();
goto cleanup; goto cleanup;
}
break; break;
default: default:
virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"), virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"),
@ -966,12 +932,9 @@ remoteDeserializeTypedParameters(remote_typed_param *args_params_val,
args_params_val[i].value.remote_typed_param_value_u.b; args_params_val[i].value.remote_typed_param_value_u.b;
break; break;
case VIR_TYPED_PARAM_STRING: case VIR_TYPED_PARAM_STRING:
params[i].value.s = if (VIR_STRDUP(params[i].value.s,
strdup(args_params_val[i].value.remote_typed_param_value_u.s); args_params_val[i].value.remote_typed_param_value_u.s) < 0)
if (params[i].value.s == NULL) {
virReportOOMError();
goto cleanup; goto cleanup;
}
break; break;
default: default:
virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown parameter type: %d"), virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown parameter type: %d"),
@ -2152,9 +2115,8 @@ remoteDispatchNodeGetCPUStats(virNetServerPtr server ATTRIBUTE_UNUSED,
for (i = 0; i < nparams; ++i) { for (i = 0; i < nparams; ++i) {
/* remoteDispatchClientRequest will free this: */ /* remoteDispatchClientRequest will free this: */
ret->params.params_val[i].field = strdup(params[i].field); if (VIR_STRDUP(ret->params.params_val[i].field, params[i].field) < 0)
if (ret->params.params_val[i].field == NULL) goto cleanup;
goto no_memory;
ret->params.params_val[i].value = params[i].value; ret->params.params_val[i].value = params[i].value;
} }
@ -2231,9 +2193,8 @@ remoteDispatchNodeGetMemoryStats(virNetServerPtr server ATTRIBUTE_UNUSED,
for (i = 0; i < nparams; ++i) { for (i = 0; i < nparams; ++i) {
/* remoteDispatchClientRequest will free this: */ /* remoteDispatchClientRequest will free this: */
ret->params.params_val[i].field = strdup(params[i].field); if (VIR_STRDUP(ret->params.params_val[i].field, params[i].field) < 0)
if (ret->params.params_val[i].field == NULL) goto cleanup;
goto no_memory;
ret->params.params_val[i].value = params[i].value; ret->params.params_val[i].value = params[i].value;
} }
@ -3109,9 +3070,8 @@ remoteDispatchNodeDeviceGetParent(virNetServerPtr server ATTRIBUTE_UNUSED,
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
if (!(*parent_p = strdup(parent))) { if (VIR_STRDUP(*parent_p, parent) < 0) {
VIR_FREE(parent_p); VIR_FREE(parent_p);
virReportOOMError();
goto cleanup; goto cleanup;
} }
ret->parent = parent_p; ret->parent = parent_p;
@ -4779,14 +4739,14 @@ static void
make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPtr dom_src) make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPtr dom_src)
{ {
dom_dst->id = dom_src->id; dom_dst->id = dom_src->id;
dom_dst->name = strdup(dom_src->name); ignore_value(VIR_STRDUP_QUIET(dom_dst->name, dom_src->name));
memcpy(dom_dst->uuid, dom_src->uuid, VIR_UUID_BUFLEN); memcpy(dom_dst->uuid, dom_src->uuid, VIR_UUID_BUFLEN);
} }
static void static void
make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_src) make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_src)
{ {
net_dst->name = strdup(net_src->name); ignore_value(VIR_STRDUP_QUIET(net_dst->name, net_src->name));
memcpy(net_dst->uuid, net_src->uuid, VIR_UUID_BUFLEN); memcpy(net_dst->uuid, net_src->uuid, VIR_UUID_BUFLEN);
} }
@ -4794,29 +4754,29 @@ static void
make_nonnull_interface(remote_nonnull_interface *interface_dst, make_nonnull_interface(remote_nonnull_interface *interface_dst,
virInterfacePtr interface_src) virInterfacePtr interface_src)
{ {
interface_dst->name = strdup(interface_src->name); ignore_value(VIR_STRDUP_QUIET(interface_dst->name, interface_src->name));
interface_dst->mac = strdup(interface_src->mac); ignore_value(VIR_STRDUP_QUIET(interface_dst->mac, interface_src->mac));
} }
static void static void
make_nonnull_storage_pool(remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr pool_src) make_nonnull_storage_pool(remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr pool_src)
{ {
pool_dst->name = strdup(pool_src->name); ignore_value(VIR_STRDUP_QUIET(pool_dst->name, pool_src->name));
memcpy(pool_dst->uuid, pool_src->uuid, VIR_UUID_BUFLEN); memcpy(pool_dst->uuid, pool_src->uuid, VIR_UUID_BUFLEN);
} }
static void static void
make_nonnull_storage_vol(remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src) make_nonnull_storage_vol(remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src)
{ {
vol_dst->pool = strdup(vol_src->pool); ignore_value(VIR_STRDUP_QUIET(vol_dst->pool, vol_src->pool));
vol_dst->name = strdup(vol_src->name); ignore_value(VIR_STRDUP_QUIET(vol_dst->name, vol_src->name));
vol_dst->key = strdup(vol_src->key); ignore_value(VIR_STRDUP_QUIET(vol_dst->key, vol_src->key));
} }
static void static void
make_nonnull_node_device(remote_nonnull_node_device *dev_dst, virNodeDevicePtr dev_src) make_nonnull_node_device(remote_nonnull_node_device *dev_dst, virNodeDevicePtr dev_src)
{ {
dev_dst->name = strdup(dev_src->name); ignore_value(VIR_STRDUP_QUIET(dev_dst->name, dev_src->name));
} }
static void static void
@ -4824,20 +4784,20 @@ make_nonnull_secret(remote_nonnull_secret *secret_dst, virSecretPtr secret_src)
{ {
memcpy(secret_dst->uuid, secret_src->uuid, VIR_UUID_BUFLEN); memcpy(secret_dst->uuid, secret_src->uuid, VIR_UUID_BUFLEN);
secret_dst->usageType = secret_src->usageType; secret_dst->usageType = secret_src->usageType;
secret_dst->usageID = strdup(secret_src->usageID); ignore_value(VIR_STRDUP_QUIET(secret_dst->usageID, secret_src->usageID));
} }
static void static void
make_nonnull_nwfilter(remote_nonnull_nwfilter *nwfilter_dst, virNWFilterPtr nwfilter_src) make_nonnull_nwfilter(remote_nonnull_nwfilter *nwfilter_dst, virNWFilterPtr nwfilter_src)
{ {
nwfilter_dst->name = strdup(nwfilter_src->name); ignore_value(VIR_STRDUP_QUIET(nwfilter_dst->name, nwfilter_src->name));
memcpy(nwfilter_dst->uuid, nwfilter_src->uuid, VIR_UUID_BUFLEN); memcpy(nwfilter_dst->uuid, nwfilter_src->uuid, VIR_UUID_BUFLEN);
} }
static void static void
make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapshot_dst, virDomainSnapshotPtr snapshot_src) make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapshot_dst, virDomainSnapshotPtr snapshot_src)
{ {
snapshot_dst->name = strdup(snapshot_src->name); ignore_value(VIR_STRDUP_QUIET(snapshot_dst->name, snapshot_src->name));
make_nonnull_domain(&snapshot_dst->dom, snapshot_src->domain); make_nonnull_domain(&snapshot_dst->dom, snapshot_src->domain);
} }
@ -4850,12 +4810,14 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors,
remote_domain_disk_error *val = NULL; remote_domain_disk_error *val = NULL;
int i = 0; int i = 0;
if (VIR_ALLOC_N(val, nerrors) < 0) if (VIR_ALLOC_N(val, nerrors) < 0) {
goto no_memory; virReportOOMError();
goto error;
}
for (i = 0; i < nerrors; i++) { for (i = 0; i < nerrors; i++) {
if (!(val[i].disk = strdup(errors[i].disk))) if (VIR_STRDUP(val[i].disk, errors[i].disk) < 0)
goto no_memory; goto error;
val[i].error = errors[i].error; val[i].error = errors[i].error;
} }
@ -4864,13 +4826,12 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors,
return 0; return 0;
no_memory: error:
if (val) { if (val) {
int j; int j;
for (j = 0; j < i; j++) for (j = 0; j < i; j++)
VIR_FREE(val[j].disk); VIR_FREE(val[j].disk);
VIR_FREE(val); VIR_FREE(val);
} }
virReportOOMError();
return -1; return -1;
} }