When growing the buffer when it's not big enough for new data, the
current size is doubled repeatedly until it is big enough for the new
data. The required new size is stored in the variable "required",
however the doubling loop exited when the new size was at least
buf->used + len, which might be much smaller than "required" if an
out-of-order packet is received.
} else {
do {
newsize *= 2;
- } while(newsize < buf->used + len);
+ } while(newsize < required);
}
if(newsize > buf->maxsize)
newsize = buf->maxsize;