summaryrefslogtreecommitdiff
path: root/src/rpc/virnetmessage.c
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/virnetmessage.c
parent7bff56a0d1514cb955eb14adc14281626e80e96c (diff)
downloadlibvirt-a2c304f6872f15c13c1cd642b74008009f7e115b.tar.gz
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/virnetmessage.c')
-rw-r--r--src/rpc/virnetmessage.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c
index 17ecc90eb7..dc4c2127a8 100644
--- a/src/rpc/virnetmessage.c
+++ b/src/rpc/virnetmessage.c
@@ -61,6 +61,7 @@ void virNetMessageClear(virNetMessagePtr msg)
for (i = 0 ; i < msg->nfds ; i++)
VIR_FORCE_CLOSE(msg->fds[i]);
VIR_FREE(msg->fds);
+ VIR_FREE(msg->buffer);
memset(msg, 0, sizeof(*msg));
msg->tracked = tracked;
}
@@ -79,6 +80,7 @@ void virNetMessageFree(virNetMessagePtr msg)
for (i = 0 ; i < msg->nfds ; i++)
VIR_FORCE_CLOSE(msg->fds[i]);
+ VIR_FREE(msg->buffer);
VIR_FREE(msg->fds);
VIR_FREE(msg);
}
@@ -144,6 +146,10 @@ int virNetMessageDecodeLength(virNetMessagePtr msg)
/* Extend our declared buffer length and carry
on reading the header + payload */
msg->bufferLength += len;
+ if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
VIR_DEBUG("Got length, now need %zu total (%u more)",
msg->bufferLength, len);
@@ -212,7 +218,11 @@ int virNetMessageEncodeHeader(virNetMessagePtr msg)
int ret = -1;
unsigned int len = 0;
- msg->bufferLength = sizeof(msg->buffer);
+ msg->bufferLength = VIR_NET_MESSAGE_MAX + VIR_NET_MESSAGE_LEN_MAX;
+ if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
msg->bufferOffset = 0;
/* Format the header. */