Adapt to VIR_ALLOC and virAsprintf in src/rpc/*

This commit is contained in:
Michal Privoznik 2013-07-04 12:15:05 +02:00
parent 7be0e3c9d8
commit ff50bdfda3
13 changed files with 60 additions and 153 deletions

View File

@ -661,10 +661,8 @@ elsif ($mode eq "server") {
push(@free_list, " VIR_FREE($1);"); push(@free_list, " VIR_FREE($1);");
push(@free_list_on_error, "VIR_FREE($1_p);"); push(@free_list_on_error, "VIR_FREE($1_p);");
push(@prepare_ret_list, push(@prepare_ret_list,
"if (VIR_ALLOC($1_p) < 0) {\n" . "if (VIR_ALLOC($1_p) < 0)\n" .
" virReportOOMError();\n" .
" goto cleanup;\n" . " goto cleanup;\n" .
" }\n" .
" \n" . " \n" .
" if (VIR_STRDUP(*$1_p, $1) < 0)\n". " if (VIR_STRDUP(*$1_p, $1) < 0)\n".
" goto cleanup;\n"); " goto cleanup;\n");
@ -932,10 +930,8 @@ elsif ($mode eq "server") {
if ($single_ret_as_list) { if ($single_ret_as_list) {
print " /* Allocate return buffer. */\n"; print " /* Allocate return buffer. */\n";
print " if (VIR_ALLOC_N(ret->$single_ret_list_name.${single_ret_list_name}_val," . print " if (VIR_ALLOC_N(ret->$single_ret_list_name.${single_ret_list_name}_val," .
" args->$single_ret_list_max_var) < 0) {\n"; " args->$single_ret_list_max_var) < 0)\n";
print " virReportOOMError();\n";
print " goto cleanup;\n"; print " goto cleanup;\n";
print " }\n";
print "\n"; print "\n";
} }

View File

@ -875,15 +875,14 @@ int virNetClientAddProgram(virNetClientPtr client,
virObjectLock(client); virObjectLock(client);
if (VIR_EXPAND_N(client->programs, client->nprograms, 1) < 0) if (VIR_EXPAND_N(client->programs, client->nprograms, 1) < 0)
goto no_memory; goto error;
client->programs[client->nprograms-1] = virObjectRef(prog); client->programs[client->nprograms-1] = virObjectRef(prog);
virObjectUnlock(client); virObjectUnlock(client);
return 0; return 0;
no_memory: error:
virReportOOMError();
virObjectUnlock(client); virObjectUnlock(client);
return -1; return -1;
} }
@ -895,15 +894,14 @@ int virNetClientAddStream(virNetClientPtr client,
virObjectLock(client); virObjectLock(client);
if (VIR_EXPAND_N(client->streams, client->nstreams, 1) < 0) if (VIR_EXPAND_N(client->streams, client->nstreams, 1) < 0)
goto no_memory; goto error;
client->streams[client->nstreams-1] = virObjectRef(st); client->streams[client->nstreams-1] = virObjectRef(st);
virObjectUnlock(client); virObjectUnlock(client);
return 0; return 0;
no_memory: error:
virReportOOMError();
virObjectUnlock(client); virObjectUnlock(client);
return -1; return -1;
} }
@ -981,10 +979,8 @@ virNetClientCallDispatchReply(virNetClientPtr client)
return -1; return -1;
} }
if (VIR_REALLOC_N(thecall->msg->buffer, client->msg.bufferLength) < 0) { if (VIR_REALLOC_N(thecall->msg->buffer, client->msg.bufferLength) < 0)
virReportOOMError();
return -1; return -1;
}
memcpy(thecall->msg->buffer, client->msg.buffer, client->msg.bufferLength); memcpy(thecall->msg->buffer, client->msg.buffer, client->msg.bufferLength);
memcpy(&thecall->msg->header, &client->msg.header, sizeof(client->msg.header)); memcpy(&thecall->msg->header, &client->msg.header, sizeof(client->msg.header));
@ -1233,10 +1229,8 @@ virNetClientIOReadMessage(virNetClientPtr client)
/* Start by reading length word */ /* Start by reading length word */
if (client->msg.bufferLength == 0) { if (client->msg.bufferLength == 0) {
client->msg.bufferLength = 4; client->msg.bufferLength = 4;
if (VIR_ALLOC_N(client->msg.buffer, client->msg.bufferLength) < 0) { if (VIR_ALLOC_N(client->msg.buffer, client->msg.bufferLength) < 0)
virReportOOMError();
return -ENOMEM; return -ENOMEM;
}
} }
wantData = client->msg.bufferLength - client->msg.bufferOffset; wantData = client->msg.bufferLength - client->msg.bufferOffset;
@ -1888,10 +1882,8 @@ virNetClientCallNew(virNetMessagePtr msg,
goto error; goto error;
} }
if (VIR_ALLOC(call) < 0) { if (VIR_ALLOC(call) < 0)
virReportOOMError();
goto error; goto error;
}
if (virCondInit(&call->cond) < 0) { if (virCondInit(&call->cond) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -1964,10 +1956,8 @@ static int virNetClientSendInternal(virNetClientPtr client,
return -1; return -1;
} }
if (!(call = virNetClientCallNew(msg, expectReply, nonBlock))) { if (!(call = virNetClientCallNew(msg, expectReply, nonBlock)))
virReportOOMError();
return -1; return -1;
}
call->haveThread = true; call->haveThread = true;
ret = virNetClientIO(client, call); ret = virNetClientIO(client, call);

View File

@ -250,10 +250,8 @@ int virNetClientProgramDispatch(virNetClientProgramPtr prog,
return -1; return -1;
} }
if (VIR_ALLOC_N(evdata, event->msg_len) < 0) { if (VIR_ALLOC_N(evdata, event->msg_len) < 0)
virReportOOMError();
return -1; return -1;
}
if (virNetMessageDecodePayload(msg, event->msg_filter, evdata) < 0) if (virNetMessageDecodePayload(msg, event->msg_filter, evdata) < 0)
goto cleanup; goto cleanup;
@ -297,10 +295,8 @@ int virNetClientProgramCall(virNetClientProgramPtr prog,
msg->header.serial = serial; msg->header.serial = serial;
msg->header.proc = proc; msg->header.proc = proc;
msg->nfds = noutfds; msg->nfds = noutfds;
if (VIR_ALLOC_N(msg->fds, msg->nfds) < 0) { if (VIR_ALLOC_N(msg->fds, msg->nfds) < 0)
virReportOOMError();
goto error; goto error;
}
for (i = 0; i < msg->nfds; i++) for (i = 0; i < msg->nfds; i++)
msg->fds[i] = -1; msg->fds[i] = -1;
for (i = 0; i < msg->nfds; i++) { for (i = 0; i < msg->nfds; i++) {
@ -358,10 +354,8 @@ int virNetClientProgramCall(virNetClientProgramPtr prog,
case VIR_NET_OK: case VIR_NET_OK:
if (infds && ninfds) { if (infds && ninfds) {
*ninfds = msg->nfds; *ninfds = msg->nfds;
if (VIR_ALLOC_N(*infds, *ninfds) < 0) { if (VIR_ALLOC_N(*infds, *ninfds) < 0)
virReportOOMError();
goto error; goto error;
}
for (i = 0; i < *ninfds; i++) for (i = 0; i < *ninfds; i++)
(*infds)[i] = -1; (*infds)[i] = -1;
for (i = 0; i < *ninfds; i++) { for (i = 0; i < *ninfds; i++) {

View File

@ -373,10 +373,8 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st,
goto cleanup; goto cleanup;
} }
if (!(msg = virNetMessageNew(false))) { if (!(msg = virNetMessageNew(false)))
virReportOOMError();
goto cleanup; goto cleanup;
}
msg->header.prog = virNetClientProgramGetProgram(st->prog); msg->header.prog = virNetClientProgramGetProgram(st->prog);
msg->header.vers = virNetClientProgramGetVersion(st->prog); msg->header.vers = virNetClientProgramGetVersion(st->prog);

View File

@ -37,10 +37,8 @@ virNetMessagePtr virNetMessageNew(bool tracked)
{ {
virNetMessagePtr msg; virNetMessagePtr msg;
if (VIR_ALLOC(msg) < 0) { if (VIR_ALLOC(msg) < 0)
virReportOOMError();
return NULL; return NULL;
}
msg->tracked = tracked; msg->tracked = tracked;
VIR_DEBUG("msg=%p tracked=%d", msg, tracked); VIR_DEBUG("msg=%p tracked=%d", msg, tracked);
@ -144,10 +142,8 @@ int virNetMessageDecodeLength(virNetMessagePtr msg)
/* Extend our declared buffer length and carry /* Extend our declared buffer length and carry
on reading the header + payload */ on reading the header + payload */
msg->bufferLength += len; msg->bufferLength += len;
if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) { if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
VIR_DEBUG("Got length, now need %zu total (%u more)", VIR_DEBUG("Got length, now need %zu total (%u more)",
msg->bufferLength, len); msg->bufferLength, len);
@ -223,10 +219,8 @@ int virNetMessageEncodeHeader(virNetMessagePtr msg)
unsigned int len = 0; unsigned int len = 0;
msg->bufferLength = VIR_NET_MESSAGE_INITIAL + VIR_NET_MESSAGE_LEN_MAX; msg->bufferLength = VIR_NET_MESSAGE_INITIAL + VIR_NET_MESSAGE_LEN_MAX;
if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) { if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0)
virReportOOMError();
return ret; return ret;
}
msg->bufferOffset = 0; msg->bufferOffset = 0;
/* Format the header. */ /* Format the header. */
@ -322,10 +316,8 @@ int virNetMessageDecodeNumFDs(virNetMessagePtr msg)
} }
msg->nfds = numFDs; msg->nfds = numFDs;
if (VIR_ALLOC_N(msg->fds, msg->nfds) < 0) { if (VIR_ALLOC_N(msg->fds, msg->nfds) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < msg->nfds; i++) for (i = 0; i < msg->nfds; i++)
msg->fds[i] = -1; msg->fds[i] = -1;
@ -364,10 +356,8 @@ int virNetMessageEncodePayload(virNetMessagePtr msg,
msg->bufferLength = (msg->bufferLength - VIR_NET_MESSAGE_LEN_MAX) * 4 + msg->bufferLength = (msg->bufferLength - VIR_NET_MESSAGE_LEN_MAX) * 4 +
VIR_NET_MESSAGE_LEN_MAX; VIR_NET_MESSAGE_LEN_MAX;
if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) { if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0)
virReportOOMError();
goto error; goto error;
}
xdrmem_create(&xdr, msg->buffer + msg->bufferOffset, xdrmem_create(&xdr, msg->buffer + msg->bufferOffset,
msg->bufferLength - msg->bufferOffset, XDR_ENCODE); msg->bufferLength - msg->bufferOffset, XDR_ENCODE);
@ -445,10 +435,8 @@ int virNetMessageEncodePayloadRaw(virNetMessagePtr msg,
msg->bufferLength = msg->bufferOffset + len; msg->bufferLength = msg->bufferOffset + len;
if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) { if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0)
virReportOOMError();
return -1; return -1;
}
VIR_DEBUG("Increased message buffer length = %zu", msg->bufferLength); VIR_DEBUG("Increased message buffer length = %zu", msg->bufferLength);
} }
@ -533,7 +521,7 @@ void virNetMessageSaveError(virNetMessageErrorPtr rerr)
} else { } else {
rerr->code = VIR_ERR_INTERNAL_ERROR; rerr->code = VIR_ERR_INTERNAL_ERROR;
rerr->domain = VIR_FROM_RPC; rerr->domain = VIR_FROM_RPC;
if (VIR_ALLOC(rerr->message) == 0 && if (VIR_ALLOC_QUIET(rerr->message) == 0 &&
VIR_STRDUP_QUIET(*rerr->message, VIR_STRDUP_QUIET(*rerr->message,
_("Library function returned error but did not set virError")) < 0) _("Library function returned error but did not set virError")) < 0)
VIR_FREE(rerr->message); VIR_FREE(rerr->message);

View File

@ -221,10 +221,8 @@ static int virNetServerDispatchNewMessage(virNetServerClientPtr client,
if (srv->workers) { if (srv->workers) {
virNetServerJobPtr job; virNetServerJobPtr job;
if (VIR_ALLOC(job) < 0) { if (VIR_ALLOC(job) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
job->client = client; job->client = client;
job->msg = msg; job->msg = msg;
@ -267,10 +265,8 @@ static int virNetServerAddClient(virNetServerPtr srv,
if (virNetServerClientInit(client) < 0) if (virNetServerClientInit(client) < 0)
goto error; goto error;
if (VIR_EXPAND_N(srv->clients, srv->nclients, 1) < 0) { if (VIR_EXPAND_N(srv->clients, srv->nclients, 1) < 0)
virReportOOMError();
goto error; goto error;
}
srv->clients[srv->nclients-1] = client; srv->clients[srv->nclients-1] = client;
virObjectRef(client); virObjectRef(client);
@ -933,10 +929,10 @@ int virNetServerAddSignalHandler(virNetServerPtr srv,
goto error; goto error;
if (VIR_EXPAND_N(srv->signals, srv->nsignals, 1) < 0) if (VIR_EXPAND_N(srv->signals, srv->nsignals, 1) < 0)
goto no_memory; goto error;
if (VIR_ALLOC(sigdata) < 0) if (VIR_ALLOC(sigdata) < 0)
goto no_memory; goto error;
sigdata->signum = signum; sigdata->signum = signum;
sigdata->func = func; sigdata->func = func;
@ -954,8 +950,6 @@ int virNetServerAddSignalHandler(virNetServerPtr srv,
virObjectUnlock(srv); virObjectUnlock(srv);
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
VIR_FREE(sigdata); VIR_FREE(sigdata);
virObjectUnlock(srv); virObjectUnlock(srv);
@ -971,7 +965,7 @@ int virNetServerAddService(virNetServerPtr srv,
virObjectLock(srv); virObjectLock(srv);
if (VIR_EXPAND_N(srv->services, srv->nservices, 1) < 0) if (VIR_EXPAND_N(srv->services, srv->nservices, 1) < 0)
goto no_memory; goto error;
if (mdnsEntryName) { if (mdnsEntryName) {
int port = virNetServerServiceGetPort(svc); int port = virNetServerServiceGetPort(svc);
@ -992,8 +986,6 @@ int virNetServerAddService(virNetServerPtr srv,
virObjectUnlock(srv); virObjectUnlock(srv);
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
virObjectUnlock(srv); virObjectUnlock(srv);
return -1; return -1;
@ -1005,15 +997,14 @@ int virNetServerAddProgram(virNetServerPtr srv,
virObjectLock(srv); virObjectLock(srv);
if (VIR_EXPAND_N(srv->programs, srv->nprograms, 1) < 0) if (VIR_EXPAND_N(srv->programs, srv->nprograms, 1) < 0)
goto no_memory; goto error;
srv->programs[srv->nprograms-1] = virObjectRef(prog); srv->programs[srv->nprograms-1] = virObjectRef(prog);
virObjectUnlock(srv); virObjectUnlock(srv);
return 0; return 0;
no_memory: error:
virReportOOMError();
virObjectUnlock(srv); virObjectUnlock(srv);
return -1; return -1;
} }

View File

@ -241,10 +241,8 @@ int virNetServerClientAddFilter(virNetServerClientPtr client,
virNetServerClientFilterPtr *place; virNetServerClientFilterPtr *place;
int ret; int ret;
if (VIR_ALLOC(filter) < 0) { if (VIR_ALLOC(filter) < 0)
virReportOOMError();
return -1; return -1;
}
virObjectLock(client); virObjectLock(client);
@ -316,7 +314,6 @@ virNetServerClientCheckAccess(virNetServerClientPtr client)
*/ */
confirm->bufferLength = 1; confirm->bufferLength = 1;
if (VIR_ALLOC_N(confirm->buffer, confirm->bufferLength) < 0) { if (VIR_ALLOC_N(confirm->buffer, confirm->bufferLength) < 0) {
virReportOOMError();
virNetMessageFree(confirm); virNetMessageFree(confirm);
return -1; return -1;
} }
@ -378,10 +375,8 @@ virNetServerClientNewInternal(virNetSocketPtr sock,
if (!(client->rx = virNetMessageNew(true))) if (!(client->rx = virNetMessageNew(true)))
goto error; goto error;
client->rx->bufferLength = VIR_NET_MESSAGE_LEN_MAX; client->rx->bufferLength = VIR_NET_MESSAGE_LEN_MAX;
if (VIR_ALLOC_N(client->rx->buffer, client->rx->bufferLength) < 0) { if (VIR_ALLOC_N(client->rx->buffer, client->rx->bufferLength) < 0)
virReportOOMError();
goto error; goto error;
}
client->nrequests = 1; client->nrequests = 1;
PROBE(RPC_SERVER_CLIENT_NEW, PROBE(RPC_SERVER_CLIENT_NEW,
@ -680,15 +675,11 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client)
if (!(groupname = virGetGroupName(gid))) if (!(groupname = virGetGroupName(gid)))
goto cleanup; goto cleanup;
if (virAsprintf(&processid, "%llu", if (virAsprintf(&processid, "%llu",
(unsigned long long)pid) < 0) { (unsigned long long)pid) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virAsprintf(&processtime, "%llu", if (virAsprintf(&processtime, "%llu",
timestamp) < 0) { timestamp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
#if WITH_SASL #if WITH_SASL
@ -1243,7 +1234,6 @@ readmore:
client->rx->bufferLength = VIR_NET_MESSAGE_LEN_MAX; client->rx->bufferLength = VIR_NET_MESSAGE_LEN_MAX;
if (VIR_ALLOC_N(client->rx->buffer, if (VIR_ALLOC_N(client->rx->buffer,
client->rx->bufferLength) < 0) { client->rx->bufferLength) < 0) {
virReportOOMError();
client->wantClose = true; client->wantClose = true;
} else { } else {
client->nrequests++; client->nrequests++;
@ -1346,7 +1336,6 @@ virNetServerClientDispatchWrite(virNetServerClientPtr client)
virNetMessageClear(msg); virNetMessageClear(msg);
msg->bufferLength = VIR_NET_MESSAGE_LEN_MAX; msg->bufferLength = VIR_NET_MESSAGE_LEN_MAX;
if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) { if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) {
virReportOOMError();
virNetMessageFree(msg); virNetMessageFree(msg);
return; return;
} }

View File

@ -273,10 +273,8 @@ static AvahiWatch *virNetServerMDNSWatchNew(const AvahiPoll *api ATTRIBUTE_UNUSE
{ {
AvahiWatch *w; AvahiWatch *w;
virEventHandleType hEvents; virEventHandleType hEvents;
if (VIR_ALLOC(w) < 0) { if (VIR_ALLOC(w) < 0)
virReportOOMError();
return NULL; return NULL;
}
w->fd = fd; w->fd = fd;
w->revents = 0; w->revents = 0;
@ -338,10 +336,8 @@ static AvahiTimeout *virNetServerMDNSTimeoutNew(const AvahiPoll *api ATTRIBUTE_U
struct timeval now; struct timeval now;
long long nowms, thenms, timeout; long long nowms, thenms, timeout;
VIR_DEBUG("Add timeout TV %p", tv); VIR_DEBUG("Add timeout TV %p", tv);
if (VIR_ALLOC(t) < 0) { if (VIR_ALLOC(t) < 0)
virReportOOMError();
return NULL; return NULL;
}
if (gettimeofday(&now, NULL) < 0) { if (gettimeofday(&now, NULL) < 0) {
virReportSystemError(errno, "%s", virReportSystemError(errno, "%s",
@ -413,10 +409,8 @@ static void virNetServerMDNSTimeoutFree(AvahiTimeout *t)
static AvahiPoll *virNetServerMDNSCreatePoll(void) static AvahiPoll *virNetServerMDNSCreatePoll(void)
{ {
AvahiPoll *p; AvahiPoll *p;
if (VIR_ALLOC(p) < 0) { if (VIR_ALLOC(p) < 0)
virReportOOMError();
return NULL; return NULL;
}
p->userdata = NULL; p->userdata = NULL;
@ -475,10 +469,8 @@ virNetServerMDNSGroupPtr virNetServerMDNSAddGroup(virNetServerMDNS *mdns,
virNetServerMDNSGroupPtr group; virNetServerMDNSGroupPtr group;
VIR_DEBUG("Adding group '%s'", name); VIR_DEBUG("Adding group '%s'", name);
if (VIR_ALLOC(group) < 0) { if (VIR_ALLOC(group) < 0)
virReportOOMError();
return NULL; return NULL;
}
if (VIR_STRDUP(group->name, name) < 0) { if (VIR_STRDUP(group->name, name) < 0) {
VIR_FREE(group); VIR_FREE(group);
@ -519,10 +511,8 @@ virNetServerMDNSEntryPtr virNetServerMDNSAddEntry(virNetServerMDNSGroupPtr group
virNetServerMDNSEntryPtr entry; virNetServerMDNSEntryPtr entry;
VIR_DEBUG("Adding entry %s %d to group %s", type, port, group->name); VIR_DEBUG("Adding entry %s %d to group %s", type, port, group->name);
if (VIR_ALLOC(entry) < 0) { if (VIR_ALLOC(entry) < 0)
virReportOOMError();
return NULL; return NULL;
}
entry->port = port; entry->port = port;
if (VIR_STRDUP(entry->type, type) < 0) { if (VIR_STRDUP(entry->type, type) < 0) {

View File

@ -408,14 +408,10 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr prog,
goto error; goto error;
} }
if (VIR_ALLOC_N(arg, dispatcher->arg_len) < 0) { if (VIR_ALLOC_N(arg, dispatcher->arg_len) < 0)
virReportOOMError();
goto error; goto error;
} if (VIR_ALLOC_N(ret, dispatcher->ret_len) < 0)
if (VIR_ALLOC_N(ret, dispatcher->ret_len) < 0) {
virReportOOMError();
goto error; goto error;
}
if (virNetMessageDecodePayload(msg, dispatcher->arg_filter, arg) < 0) if (virNetMessageDecodePayload(msg, dispatcher->arg_filter, arg) < 0)
goto error; goto error;

View File

@ -175,7 +175,7 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
svc->nsocks = 1; svc->nsocks = 1;
if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0) if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0)
goto no_memory; goto error;
if (virNetSocketNewListenUNIX(path, if (virNetSocketNewListenUNIX(path,
mask, mask,
@ -204,8 +204,6 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
return svc; return svc;
no_memory:
virReportOOMError();
error: error:
virObjectUnref(svc); virObjectUnref(svc);
return NULL; return NULL;
@ -237,7 +235,7 @@ virNetServerServicePtr virNetServerServiceNewFD(int fd,
svc->nsocks = 1; svc->nsocks = 1;
if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0) if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0)
goto no_memory; goto error;
if (virNetSocketNewListenFD(fd, if (virNetSocketNewListenFD(fd,
&svc->socks[0]) < 0) &svc->socks[0]) < 0)
@ -257,8 +255,6 @@ virNetServerServicePtr virNetServerServiceNewFD(int fd,
return svc; return svc;
no_memory:
virReportOOMError();
error: error:
virObjectUnref(svc); virObjectUnref(svc);
return NULL; return NULL;
@ -310,10 +306,8 @@ virNetServerServicePtr virNetServerServiceNewPostExecRestart(virJSONValuePtr obj
} }
svc->nsocks = n; svc->nsocks = n;
if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0) { if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0)
virReportOOMError();
goto error; goto error;
}
for (i = 0; i < svc->nsocks; i++) { for (i = 0; i < svc->nsocks; i++) {
virJSONValuePtr child = virJSONValueArrayGet(socks, i); virJSONValuePtr child = virJSONValueArrayGet(socks, i);

View File

@ -297,10 +297,8 @@ int virNetSocketNewListenTCP(const char *nodename,
VIR_DEBUG("%p f=%d f=%d", &addr, runp->ai_family, addr.data.sa.sa_family); VIR_DEBUG("%p f=%d f=%d", &addr, runp->ai_family, addr.data.sa.sa_family);
if (VIR_EXPAND_N(socks, nsocks, 1) < 0) { if (VIR_EXPAND_N(socks, nsocks, 1) < 0)
virReportOOMError();
goto error; goto error;
}
if (!(socks[nsocks-1] = virNetSocketNew(&addr, NULL, false, fd, -1, 0))) if (!(socks[nsocks-1] = virNetSocketNew(&addr, NULL, false, fd, -1, 0)))
goto error; goto error;
@ -1435,10 +1433,8 @@ static ssize_t virNetSocketReadSASL(virNetSocketPtr sock, char *buf, size_t len)
if (sock->saslDecoded == NULL) { if (sock->saslDecoded == NULL) {
ssize_t encodedLen = virNetSASLSessionGetMaxBufSize(sock->saslSession); ssize_t encodedLen = virNetSASLSessionGetMaxBufSize(sock->saslSession);
char *encoded; char *encoded;
if (VIR_ALLOC_N(encoded, encodedLen) < 0) { if (VIR_ALLOC_N(encoded, encodedLen) < 0)
virReportOOMError();
return -1; return -1;
}
encodedLen = virNetSocketReadWire(sock, encoded, encodedLen); encodedLen = virNetSocketReadWire(sock, encoded, encodedLen);
if (encodedLen <= 0) { if (encodedLen <= 0) {

View File

@ -378,7 +378,6 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess)
keyhash, keyhash,
sess->hostname, sess->port, sess->hostname, sess->port,
"y", "n") < 0) { "y", "n") < 0) {
virReportOOMError();
VIR_FREE(keyhash); VIR_FREE(keyhash);
return -1; return -1;
} }
@ -635,10 +634,8 @@ virNetSSHAuthenticatePrivkey(virNetSSHSessionPtr sess,
if (virAsprintf((char **)&retr_passphrase.prompt, if (virAsprintf((char **)&retr_passphrase.prompt,
_("Passphrase for key '%s'"), _("Passphrase for key '%s'"),
priv->filename) < 0) { priv->filename) < 0)
virReportOOMError();
return -1; return -1;
}
if (sess->cred->cb(&retr_passphrase, 1, sess->cred->cbdata)) { if (sess->cred->cb(&retr_passphrase, 1, sess->cred->cbdata)) {
virReportError(VIR_ERR_SSH, "%s", virReportError(VIR_ERR_SSH, "%s",
@ -966,10 +963,8 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess,
VIR_STRDUP(pass, password) < 0) VIR_STRDUP(pass, password) < 0)
goto error; goto error;
if (!(auth = virNetSSHSessionAuthMethodNew(sess))) { if (!(auth = virNetSSHSessionAuthMethodNew(sess)))
virReportOOMError();
goto error; goto error;
}
auth->username = user; auth->username = user;
auth->password = pass; auth->password = pass;
@ -1004,10 +999,8 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess,
if (VIR_STRDUP(user, username) < 0) if (VIR_STRDUP(user, username) < 0)
goto error; goto error;
if (!(auth = virNetSSHSessionAuthMethodNew(sess))) { if (!(auth = virNetSSHSessionAuthMethodNew(sess)))
virReportOOMError();
goto error; goto error;
}
auth->username = user; auth->username = user;
auth->method = VIR_NET_SSH_AUTH_AGENT; auth->method = VIR_NET_SSH_AUTH_AGENT;
@ -1047,10 +1040,8 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSessionPtr sess,
VIR_STRDUP(pass, password) < 0) VIR_STRDUP(pass, password) < 0)
goto error; goto error;
if (!(auth = virNetSSHSessionAuthMethodNew(sess))) { if (!(auth = virNetSSHSessionAuthMethodNew(sess)))
virReportOOMError();
goto error; goto error;
}
auth->username = user; auth->username = user;
auth->password = pass; auth->password = pass;
@ -1088,10 +1079,8 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess,
if (VIR_STRDUP(user, username) < 0) if (VIR_STRDUP(user, username) < 0)
goto error; goto error;
if (!(auth = virNetSSHSessionAuthMethodNew(sess))) { if (!(auth = virNetSSHSessionAuthMethodNew(sess)))
virReportOOMError();
goto error; goto error;
}
auth->username = user; auth->username = user;
auth->tries = tries; auth->tries = tries;

View File

@ -314,10 +314,8 @@ static int virNetTLSContextCheckCertKeyPurpose(gnutls_x509_crt_t cert,
return -1; return -1;
} }
if (VIR_ALLOC_N(buffer, size) < 0) { if (VIR_ALLOC_N(buffer, size) < 0)
virReportOOMError();
return -1; return -1;
}
status = gnutls_x509_crt_get_key_purpose_oid(cert, i, buffer, &size, &purposeCritical); status = gnutls_x509_crt_get_key_purpose_oid(cert, i, buffer, &size, &purposeCritical);
if (status < 0) { if (status < 0) {
@ -776,17 +774,17 @@ static int virNetTLSContextLocateCredentials(const char *pkipath,
VIR_DEBUG("Told to use TLS credentials in %s", pkipath); VIR_DEBUG("Told to use TLS credentials in %s", pkipath);
if ((virAsprintf(cacert, "%s/%s", pkipath, if ((virAsprintf(cacert, "%s/%s", pkipath,
"cacert.pem")) < 0) "cacert.pem")) < 0)
goto out_of_memory; goto error;
if ((virAsprintf(cacrl, "%s/%s", pkipath, if ((virAsprintf(cacrl, "%s/%s", pkipath,
"cacrl.pem")) < 0) "cacrl.pem")) < 0)
goto out_of_memory; goto error;
if ((virAsprintf(key, "%s/%s", pkipath, if ((virAsprintf(key, "%s/%s", pkipath,
isServer ? "serverkey.pem" : "clientkey.pem")) < 0) isServer ? "serverkey.pem" : "clientkey.pem")) < 0)
goto out_of_memory; goto error;
if ((virAsprintf(cert, "%s/%s", pkipath, if ((virAsprintf(cert, "%s/%s", pkipath,
isServer ? "servercert.pem" : "clientcert.pem")) < 0) isServer ? "servercert.pem" : "clientcert.pem")) < 0)
goto out_of_memory; goto error;
} else if (tryUserPkiPath) { } else if (tryUserPkiPath) {
/* Check to see if $HOME/.pki contains at least one of the /* Check to see if $HOME/.pki contains at least one of the
* files and if so, use that * files and if so, use that
@ -794,28 +792,28 @@ static int virNetTLSContextLocateCredentials(const char *pkipath,
userdir = virGetUserDirectory(); userdir = virGetUserDirectory();
if (!userdir) if (!userdir)
goto out_of_memory; goto error;
if (virAsprintf(&user_pki_path, "%s/.pki/libvirt", userdir) < 0) if (virAsprintf(&user_pki_path, "%s/.pki/libvirt", userdir) < 0)
goto out_of_memory; goto error;
VIR_DEBUG("Trying to find TLS user credentials in %s", user_pki_path); VIR_DEBUG("Trying to find TLS user credentials in %s", user_pki_path);
if ((virAsprintf(cacert, "%s/%s", user_pki_path, if ((virAsprintf(cacert, "%s/%s", user_pki_path,
"cacert.pem")) < 0) "cacert.pem")) < 0)
goto out_of_memory; goto error;
if ((virAsprintf(cacrl, "%s/%s", user_pki_path, if ((virAsprintf(cacrl, "%s/%s", user_pki_path,
"cacrl.pem")) < 0) "cacrl.pem")) < 0)
goto out_of_memory; goto error;
if ((virAsprintf(key, "%s/%s", user_pki_path, if ((virAsprintf(key, "%s/%s", user_pki_path,
isServer ? "serverkey.pem" : "clientkey.pem")) < 0) isServer ? "serverkey.pem" : "clientkey.pem")) < 0)
goto out_of_memory; goto error;
if ((virAsprintf(cert, "%s/%s", user_pki_path, if ((virAsprintf(cert, "%s/%s", user_pki_path,
isServer ? "servercert.pem" : "clientcert.pem")) < 0) isServer ? "servercert.pem" : "clientcert.pem")) < 0)
goto out_of_memory; goto error;
/* /*
* If some of the files can't be found, fallback * If some of the files can't be found, fallback
@ -864,8 +862,6 @@ static int virNetTLSContextLocateCredentials(const char *pkipath,
return 0; return 0;
out_of_memory:
virReportOOMError();
error: error:
VIR_FREE(*cacert); VIR_FREE(*cacert);
VIR_FREE(*cacrl); VIR_FREE(*cacrl);