/* Start by reading length word */
if (client->msg.bufferLength == 0) {
client->msg.bufferLength = 4;
- if (VIR_ALLOC_N(client->msg.buffer, client->msg.bufferLength) < 0)
- return -ENOMEM;
+ client->msg.buffer = g_new0(char, client->msg.bufferLength);
}
wantData = client->msg.bufferLength - client->msg.bufferOffset;
goto error;
}
- if (VIR_ALLOC(call) < 0)
- goto error;
+ call = g_new0(virNetClientCall, 1);
if (virCondInit(&call->cond) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
return -1;
}
- if (VIR_ALLOC_N(evdata, event->msg_len) < 0)
- return -1;
+ evdata = g_new0(char, event->msg_len);
if (virNetMessageDecodePayload(msg, event->msg_filter, evdata) < 0)
goto cleanup;
msg->header.type = noutfds ? VIR_NET_CALL_WITH_FDS : VIR_NET_CALL;
msg->header.serial = serial;
msg->header.proc = proc;
- if (VIR_ALLOC_N(msg->fds, noutfds) < 0)
- goto error;
+ msg->fds = g_new0(int, noutfds);
msg->nfds = noutfds;
for (i = 0; i < msg->nfds; i++)
msg->fds[i] = -1;
case VIR_NET_OK:
if (infds && ninfds) {
*ninfds = msg->nfds;
- if (VIR_ALLOC_N(*infds, *ninfds) < 0)
- goto error;
+ *infds = g_new0(int, *ninfds);
+
for (i = 0; i < *ninfds; i++)
(*infds)[i] = -1;
for (i = 0; i < *ninfds; i++) {
if (VIR_EXPAND_N(dmn->signals, dmn->nsignals, 1) < 0)
goto error;
- if (VIR_ALLOC(sigdata) < 0)
- goto error;
+ sigdata = g_new0(virNetDaemonSignal, 1);
sigdata->signum = signum;
sigdata->func = func;
{
virNetLibsshAuthMethodPtr auth;
- if (VIR_ALLOC(auth) < 0)
- goto error;
+ auth = g_new0(virNetLibsshAuthMethod, 1);
if (VIR_EXPAND_N(sess->auths, sess->nauths, 1) < 0)
goto error;
{
virNetMessagePtr msg;
- if (VIR_ALLOC(msg) < 0)
- return NULL;
+ msg = g_new0(virNetMessage, 1);
msg->tracked = tracked;
VIR_DEBUG("msg=%p tracked=%d", msg, tracked);
if (msg->nfds == 0) {
msg->nfds = numFDs;
- if (VIR_ALLOC_N(msg->fds, msg->nfds) < 0)
- goto cleanup;
+ msg->fds = g_new0(int, msg->nfds);
+
for (i = 0; i < msg->nfds; i++)
msg->fds[i] = -1;
}
if (verr) {
rerr->code = verr->code;
rerr->domain = verr->domain;
- if (verr->message && VIR_ALLOC(rerr->message) == 0)
+ if (verr->message) {
+ rerr->message = g_new0(char *, 1);
*rerr->message = g_strdup(verr->message);
+ }
rerr->level = verr->level;
- if (verr->str1 && VIR_ALLOC(rerr->str1) == 0)
+ if (verr->str1) {
+ rerr->str1 = g_new0(char *, 1);
*rerr->str1 = g_strdup(verr->str1);
- if (verr->str2 && VIR_ALLOC(rerr->str2) == 0)
+ }
+ if (verr->str2) {
+ rerr->str2 = g_new0(char *, 1);
*rerr->str2 = g_strdup(verr->str2);
- if (verr->str3 && VIR_ALLOC(rerr->str3) == 0)
+ }
+ if (verr->str3) {
+ rerr->str3 = g_new0(char *, 1);
*rerr->str3 = g_strdup(verr->str3);
+ }
rerr->int1 = verr->int1;
rerr->int2 = verr->int2;
} else {
if (virThreadPoolGetMaxWorkers(srv->workers) > 0) {
virNetServerJobPtr job;
- if (VIR_ALLOC(job) < 0)
- goto error;
+ job = g_new0(virNetServerJob, 1);
job->client = virObjectRef(client);
job->msg = msg;
virNetServerClientFilterPtr *place;
int ret;
- if (VIR_ALLOC(filter) < 0)
- return -1;
+ filter = g_new0(virNetServerClientFilter, 1);
virObjectLock(client);
* (NB. The '\1' byte is sent in an encrypted record).
*/
confirm->bufferLength = 1;
- if (VIR_ALLOC_N(confirm->buffer, confirm->bufferLength) < 0) {
- virNetMessageFree(confirm);
- return -1;
- }
+ confirm->buffer = g_new0(char, confirm->bufferLength);
confirm->bufferOffset = 0;
confirm->buffer[0] = '\1';
if (!(client->rx = virNetMessageNew(true)))
goto error;
client->rx->bufferLength = VIR_NET_MESSAGE_LEN_MAX;
- if (VIR_ALLOC_N(client->rx->buffer, client->rx->bufferLength) < 0)
- goto error;
+ client->rx->buffer = g_new0(char, client->rx->bufferLength);
client->nrequests = 1;
PROBE(RPC_SERVER_CLIENT_NEW,
client->wantClose = true;
} else {
client->rx->bufferLength = VIR_NET_MESSAGE_LEN_MAX;
- if (VIR_ALLOC_N(client->rx->buffer,
- client->rx->bufferLength) < 0) {
- client->wantClose = true;
- } else {
- client->nrequests++;
- }
+ client->rx->buffer = g_new0(char, client->rx->bufferLength);
+ client->nrequests++;
}
}
virNetServerClientUpdateEvent(client);
/* Ready to recv more messages */
virNetMessageClear(msg);
msg->bufferLength = VIR_NET_MESSAGE_LEN_MAX;
- if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) {
- virNetMessageFree(msg);
- return;
- }
+ msg->buffer = g_new0(char, msg->bufferLength);
client->rx = msg;
msg = NULL;
client->nrequests++;
goto error;
}
- if (VIR_ALLOC_N(arg, dispatcher->arg_len) < 0)
- goto error;
- if (VIR_ALLOC_N(ret, dispatcher->ret_len) < 0)
- goto error;
+ arg = g_new0(char, dispatcher->arg_len);
+ ret = g_new0(char, dispatcher->ret_len);
if (virNetMessageDecodePayload(msg, dispatcher->arg_filter, arg) < 0)
goto error;
if (!(svc = virObjectNew(virNetServerServiceClass)))
return NULL;
- if (VIR_ALLOC_N(svc->socks, nsocks) < 0)
- goto error;
+ svc->socks = g_new0(virNetSocketPtr, nsocks);
svc->nsocks = nsocks;
for (i = 0; i < svc->nsocks; i++) {
svc->socks[i] = socks[i];
virNetSocketPtr *socks;
size_t i;
- if (VIR_ALLOC_N(socks, nfds) < 0)
- goto cleanup;
+ socks = g_new0(virNetSocketPtr, nfds);
for (i = 0; i < nfds; i++) {
if (virNetSocketNewListenFD(fds[i],
}
n = virJSONValueArraySize(socks);
- if (VIR_ALLOC_N(svc->socks, n) < 0)
- goto error;
+ svc->socks = g_new0(virNetSocketPtr, n);
svc->nsocks = n;
for (i = 0; i < svc->nsocks; i++) {
if (sock->saslDecoded == NULL) {
ssize_t encodedLen = virNetSASLSessionGetMaxBufSize(sock->saslSession);
char *encoded;
- if (VIR_ALLOC_N(encoded, encodedLen) < 0)
- return -1;
+ encoded = g_new0(char, encodedLen);
encodedLen = virNetSocketReadWire(sock, encoded, encodedLen);
if (encodedLen <= 0) {
{
virNetSSHAuthMethodPtr auth;
- if (VIR_ALLOC(auth) < 0)
- goto error;
+ auth = g_new0(virNetSSHAuthMethod, 1);
if (VIR_EXPAND_N(sess->auths, sess->nauths, 1) < 0)
goto error;
return;
}
- if (VIR_ALLOC_N(askcred, num_prompts) < 0) {
- priv->authCbErr = VIR_NET_SSH_AUTHCB_OOM;
- return;
- }
+ askcred = g_new0(virConnectCredential, num_prompts);
/* fill data structures for auth callback */
for (i = 0; i < num_prompts; i++) {
return -1;
}
- if (VIR_ALLOC_N(buffer, size) < 0)
- return -1;
-
+ buffer = g_new0(char, size);
status = gnutls_x509_crt_get_key_purpose_oid(cert, i, buffer, &size, &purposeCritical);
if (status < 0) {
VIR_FREE(buffer);