--- src/remote/remote_driver.c | 79 ++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 97be2a0..89e0e96 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -368,7 +368,7 @@ remoteClientCloseFunc(virNetClientPtr client ATTRIBUTE_UNUSED, #define EXTRACT_URI_ARG_STR(ARG_NAME, ARG_VAR) \ if (STRCASEEQ(var->name, ARG_NAME)) { \ VIR_FREE(ARG_VAR); \ - if (!(ARG_VAR = strdup(var->value))) \ + if (VIR_STRDUP(ARG_VAR, var->value) < 0) \ goto no_memory; \ var->ignore = 1; \ continue; \ @@ -497,23 +497,20 @@ doRemoteOpen(virConnectPtr conn, if (virAsprintf(&port, "%d", conn->uri->port) < 0) goto no_memory; } else if (transport == trans_tls) { - if (!(port = strdup(LIBVIRTD_TLS_PORT))) + if (VIR_STRDUP(port, LIBVIRTD_TLS_PORT) < 0) goto no_memory; } else if (transport == trans_tcp) { - if (!(port = strdup(LIBVIRTD_TCP_PORT))) + if (VIR_STRDUP(port, LIBVIRTD_TCP_PORT) < 0) goto no_memory; } /* Port not used for unix, ext., default for ssh */ - if (conn->uri && conn->uri->server) - priv->hostname = strdup(conn->uri->server); - else - priv->hostname = strdup("localhost"); - - if (!priv->hostname) + if (VIR_STRDUP(priv->hostname, + conn->uri && conn->uri->server ? + conn->uri->server : "localhost") < 0) goto no_memory; if (conn->uri && conn->uri->user && - !(username = strdup(conn->uri->user))) + VIR_STRDUP(username, conn->uri->user) < 0) goto no_memory; /* Get the variables from the query string. @@ -557,7 +554,7 @@ doRemoteOpen(virConnectPtr conn, (STREQ(conn->uri->scheme, "remote") || STRPREFIX(conn->uri->scheme, "remote+"))) { /* Allow remote serve to probe */ - if (!(name = strdup(""))) + if (VIR_STRDUP(name, "") < 0) goto no_memory; } else { virURI tmpuri = { @@ -587,7 +584,7 @@ doRemoteOpen(virConnectPtr conn, } } else { /* Probe URI server side */ - if (!(name = strdup(""))) + if (VIR_STRDUP(name, "") < 0) goto no_memory; } @@ -636,12 +633,10 @@ doRemoteOpen(virConnectPtr conn, case trans_libssh2: if (!sockname) { - if (flags & VIR_DRV_OPEN_REMOTE_RO) - sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO); - else - sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET); - - if (sockname == NULL) + if (VIR_STRDUP(sockname, + flags & VIR_DRV_OPEN_REMOTE_RO ? + LIBVIRTD_PRIV_UNIX_SOCKET_RO : + LIBVIRTD_PRIV_UNIX_SOCKET) < 0) goto no_memory; } @@ -678,11 +673,10 @@ doRemoteOpen(virConnectPtr conn, } VIR_FREE(userdir); } else { - if (flags & VIR_DRV_OPEN_REMOTE_RO) - sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO); - else - sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET); - if (sockname == NULL) + if (VIR_STRDUP(sockname, + flags & VIR_DRV_OPEN_REMOTE_RO ? + LIBVIRTD_PRIV_UNIX_SOCKET_RO : + LIBVIRTD_PRIV_UNIX_SOCKET) < 0) goto no_memory; } VIR_DEBUG("Proceeding with sockname %s", sockname); @@ -705,15 +699,14 @@ doRemoteOpen(virConnectPtr conn, break; case trans_ssh: - if (!command && !(command = strdup("ssh"))) + if (!command && VIR_STRDUP(command, "ssh") < 0) goto no_memory; if (!sockname) { - if (flags & VIR_DRV_OPEN_REMOTE_RO) - sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO); - else - sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET); - if (!sockname) + if (VIR_STRDUP(sockname, + flags & VIR_DRV_OPEN_REMOTE_RO ? + LIBVIRTD_PRIV_UNIX_SOCKET_RO : + LIBVIRTD_PRIV_UNIX_SOCKET) < 0) goto no_memory; } @@ -1493,8 +1486,7 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, for (i = 0; i < nparams; ++i) { /* call() will free this: */ - val[i].field = strdup(params[i].field); - if (val[i].field == NULL) { + if (VIR_STRDUP(val[i].field, params[i].field) < 0) { virReportOOMError(); goto cleanup; } @@ -1519,8 +1511,7 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, val[i].value.remote_typed_param_value_u.b = params[i].value.b; break; case VIR_TYPED_PARAM_STRING: - val[i].value.remote_typed_param_value_u.s = strdup(params[i].value.s); - if (val[i].value.remote_typed_param_value_u.s == NULL) { + if (VIR_STRDUP(val[i].value.remote_typed_param_value_u.s, params[i].value.s) < 0) { virReportOOMError(); goto cleanup; } @@ -1608,9 +1599,8 @@ remoteDeserializeTypedParameters(remote_typed_param *ret_params_val, ret_param->value.remote_typed_param_value_u.b; break; case VIR_TYPED_PARAM_STRING: - param->value.s = - strdup(ret_param->value.remote_typed_param_value_u.s); - if (!param->value.s) { + if (VIR_STRDUP(param->value.s, + ret_param->value.remote_typed_param_value_u.s) < 0) { virReportOOMError(); goto cleanup; } @@ -1653,7 +1643,7 @@ remoteDeserializeDomainDiskErrors(remote_domain_disk_error *ret_errors_val, } for (i = 0; i < ret_errors_len; i++) { - if (!(errors[i].disk = strdup(ret_errors_val[i].disk))) { + if (VIR_STRDUP(errors[i].disk, ret_errors_val[i].disk) < 0) { virReportOOMError(); goto error; } @@ -4472,15 +4462,15 @@ remoteDomainBuildEventGraphics(virNetClientProgramPtr prog ATTRIBUTE_UNUSED, if (VIR_ALLOC(localAddr) < 0) goto no_memory; localAddr->family = msg->local.family; - if (!(localAddr->service = strdup(msg->local.service)) || - !(localAddr->node = strdup(msg->local.node))) + if (VIR_STRDUP(localAddr->service, msg->local.service) < 0 || + VIR_STRDUP(localAddr->node, msg->local.node) < 0) goto no_memory; if (VIR_ALLOC(remoteAddr) < 0) goto no_memory; remoteAddr->family = msg->remote.family; - if (!(remoteAddr->service = strdup(msg->remote.service)) || - !(remoteAddr->node = strdup(msg->remote.node))) + if (VIR_STRDUP(remoteAddr->service, msg->remote.service) < 0 || + VIR_STRDUP(remoteAddr->node, msg->remote.node) < 0) goto no_memory; if (VIR_ALLOC(subject) < 0) @@ -4489,8 +4479,8 @@ remoteDomainBuildEventGraphics(virNetClientProgramPtr prog ATTRIBUTE_UNUSED, goto no_memory; subject->nidentity = msg->subject.subject_len; for (i = 0 ; i < subject->nidentity ; i++) { - if (!(subject->identities[i].type = strdup(msg->subject.subject_val[i].type)) || - !(subject->identities[i].name = strdup(msg->subject.subject_val[i].name))) + if (VIR_STRDUP(subject->identities[i].type, msg->subject.subject_val[i].type) < 0 || + VIR_STRDUP(subject->identities[i].name, msg->subject.subject_val[i].name) < 0) goto no_memory; } @@ -5100,8 +5090,7 @@ remoteDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd, (xdrproc_t) xdr_qemu_domain_monitor_command_ret, (char *) &ret) == -1) goto done; - *result = strdup(ret.result); - if (*result == NULL) { + if (VIR_STRDUP(*result, ret.result) < 0) { virReportOOMError(); goto cleanup; } -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list