From: Michal Privoznik Date: Mon, 22 May 2017 09:44:26 +0000 (+0200) Subject: virStreamSparseSendAll: Reset @want in each iteration X-Git-Tag: v3.4.0-rc1~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b991d023709431edd922c9c5b23c1c27b043b8b;p=thirdparty%2Flibvirt.git virStreamSparseSendAll: Reset @want in each iteration There's a slight problem with the current function. Assume we are currently in a data section and we have say 42 bytes until next section. Therefore, just before (handler) is called to fill up the buffer with data, @want is changed to 42 to match the amount of data left in the current section. However, after hole is processed, we are back in data section but with incredibly small @want size. Nobody will ever reset it back. This results in incredible data fragmentation. Signed-off-by: Michal Privoznik --- diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c index ed0ed7325d..d7a8f58160 100644 --- a/src/libvirt-stream.c +++ b/src/libvirt-stream.c @@ -698,7 +698,7 @@ int virStreamSparseSendAll(virStreamPtr stream, void *opaque) { char *bytes = NULL; - size_t want = VIR_NET_MESSAGE_LEGACY_PAYLOAD_MAX; + size_t bufLen = VIR_NET_MESSAGE_LEGACY_PAYLOAD_MAX; int ret = -1; unsigned long long dataLen = 0; @@ -718,12 +718,13 @@ int virStreamSparseSendAll(virStreamPtr stream, goto cleanup; } - if (VIR_ALLOC_N(bytes, want) < 0) + if (VIR_ALLOC_N(bytes, bufLen) < 0) goto cleanup; for (;;) { int inData, got, offset = 0; long long sectionLen; + size_t want = bufLen; const unsigned int skipFlags = 0; if (!dataLen) {