aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Privoznik <mprivozn@redhat.com>2012-04-26 17:21:24 +0200
committerMichal Privoznik <mprivozn@redhat.com>2012-06-05 17:48:40 +0200
commita2c304f6872f15c13c1cd642b74008009f7e115b (patch)
tree8793b5fd047250dc598014d872928b8f1a7173a6 /src/rpc/virnetclient.c
parentbuild: fix 'make distcheck' issues (diff)
downloadlibvirt-a2c304f6872f15c13c1cd642b74008009f7e115b.tar.gz
libvirt-a2c304f6872f15c13c1cd642b74008009f7e115b.tar.bz2
libvirt-a2c304f6872f15c13c1cd642b74008009f7e115b.zip
rpc: Switch to dynamically allocated message buffer
Currently, we are allocating buffer for RPC messages statically. This is not such pain when RPC limits are small. However, if we want ever to increase those limits, we need to allocate buffer dynamically, based on RPC message len (= the first 4 bytes). Therefore we will decrease our mem usage in most cases and still be flexible enough in corner cases.
Diffstat (limited to 'src/rpc/virnetclient.c')
-rw-r--r--src/rpc/virnetclient.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index d88288d92..14f806f99 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -801,7 +801,12 @@ virNetClientCallDispatchReply(virNetClientPtr client)
return -1;
}
- memcpy(thecall->msg->buffer, client->msg.buffer, sizeof(client->msg.buffer));
+ if (VIR_REALLOC_N(thecall->msg->buffer, client->msg.bufferLength) < 0) {
+ virReportOOMError();
+ return -1;
+ }
+
+ memcpy(thecall->msg->buffer, client->msg.buffer, client->msg.bufferLength);
memcpy(&thecall->msg->header, &client->msg.header, sizeof(client->msg.header));
thecall->msg->bufferLength = client->msg.bufferLength;
thecall->msg->bufferOffset = client->msg.bufferOffset;
@@ -987,6 +992,7 @@ virNetClientIOWriteMessage(virNetClientPtr client,
}
thecall->msg->donefds = 0;
thecall->msg->bufferOffset = thecall->msg->bufferLength = 0;
+ VIR_FREE(thecall->msg->buffer);
if (thecall->expectReply)
thecall->mode = VIR_NET_CLIENT_MODE_WAIT_RX;
else
@@ -1030,8 +1036,13 @@ virNetClientIOReadMessage(virNetClientPtr client)
ssize_t ret;
/* Start by reading length word */
- if (client->msg.bufferLength == 0)
+ if (client->msg.bufferLength == 0) {
client->msg.bufferLength = 4;
+ if (VIR_ALLOC_N(client->msg.buffer, client->msg.bufferLength) < 0) {
+ virReportOOMError();
+ return -ENOMEM;
+ }
+ }
wantData = client->msg.bufferLength - client->msg.bufferOffset;
@@ -1108,6 +1119,7 @@ virNetClientIOHandleInput(virNetClientPtr client)
ret = virNetClientCallDispatch(client);
client->msg.bufferOffset = client->msg.bufferLength = 0;
+ VIR_FREE(client->msg.buffer);
/*
* We've completed one call, but we don't want to
* spin around the loop forever if there are many