mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
rpc: use g_new0 instead of VIR_ALLOC
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
99c709765a
commit
71ec40e917
@ -1435,8 +1435,7 @@ virNetClientIOReadMessage(virNetClientPtr client)
|
||||
/* 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;
|
||||
@ -2107,8 +2106,7 @@ virNetClientCallNew(virNetMessagePtr msg,
|
||||
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",
|
||||
|
@ -247,8 +247,7 @@ int virNetClientProgramDispatch(virNetClientProgramPtr prog,
|
||||
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;
|
||||
@ -291,8 +290,7 @@ int virNetClientProgramCall(virNetClientProgramPtr prog,
|
||||
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;
|
||||
@ -351,8 +349,8 @@ int virNetClientProgramCall(virNetClientProgramPtr prog,
|
||||
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++) {
|
||||
|
@ -673,8 +673,7 @@ virNetDaemonAddSignalHandler(virNetDaemonPtr dmn,
|
||||
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;
|
||||
|
@ -185,8 +185,7 @@ virNetLibsshSessionAuthMethodNew(virNetLibsshSessionPtr sess)
|
||||
{
|
||||
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;
|
||||
|
@ -38,8 +38,7 @@ virNetMessagePtr virNetMessageNew(bool tracked)
|
||||
{
|
||||
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);
|
||||
@ -328,8 +327,8 @@ int virNetMessageDecodeNumFDs(virNetMessagePtr msg)
|
||||
|
||||
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;
|
||||
}
|
||||
@ -525,15 +524,23 @@ void virNetMessageSaveError(virNetMessageErrorPtr rerr)
|
||||
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 {
|
||||
|
@ -211,8 +211,7 @@ virNetServerDispatchNewMessage(virNetServerClientPtr client,
|
||||
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;
|
||||
|
@ -240,8 +240,7 @@ int virNetServerClientAddFilter(virNetServerClientPtr client,
|
||||
virNetServerClientFilterPtr *place;
|
||||
int ret;
|
||||
|
||||
if (VIR_ALLOC(filter) < 0)
|
||||
return -1;
|
||||
filter = g_new0(virNetServerClientFilter, 1);
|
||||
|
||||
virObjectLock(client);
|
||||
|
||||
@ -311,10 +310,7 @@ virNetServerClientCheckAccess(virNetServerClientPtr 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';
|
||||
|
||||
@ -414,8 +410,7 @@ virNetServerClientNewInternal(unsigned long long id,
|
||||
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,
|
||||
@ -1306,12 +1301,8 @@ static virNetMessagePtr virNetServerClientDispatchRead(virNetServerClientPtr cli
|
||||
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);
|
||||
@ -1411,10 +1402,7 @@ virNetServerClientDispatchWrite(virNetServerClientPtr 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++;
|
||||
|
@ -403,10 +403,8 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr prog,
|
||||
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;
|
||||
|
@ -106,8 +106,7 @@ virNetServerServiceNewSocket(virNetSocketPtr *socks,
|
||||
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];
|
||||
@ -230,8 +229,7 @@ virNetServerServicePtr virNetServerServiceNewFDs(int *fds,
|
||||
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],
|
||||
@ -301,8 +299,7 @@ virNetServerServicePtr virNetServerServiceNewPostExecRestart(virJSONValuePtr obj
|
||||
}
|
||||
|
||||
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++) {
|
||||
|
@ -1876,8 +1876,7 @@ static ssize_t virNetSocketReadSASL(virNetSocketPtr sock, char *buf, size_t len)
|
||||
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) {
|
||||
|
@ -173,8 +173,7 @@ virNetSSHSessionAuthMethodNew(virNetSSHSessionPtr sess)
|
||||
{
|
||||
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;
|
||||
@ -223,10 +222,7 @@ virNetSSHKbIntCb(const char *name G_GNUC_UNUSED,
|
||||
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++) {
|
||||
|
@ -299,9 +299,7 @@ static int virNetTLSContextCheckCertKeyPurpose(gnutls_x509_crt_t cert,
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user