mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-20 00:00:10 +02:00
Fix reserve over allocating underlying buffer (#560)
Fixes calls to `reserve` when the underlying shared buffer was already big enough to fit the requested capacity. Previously a new even larger buffer was created anyways. This could eventually lead to an OOM condition.
This commit is contained in:
+4
-1
@@ -670,7 +670,10 @@ impl BytesMut {
|
||||
|
||||
// Compare the condition in the `kind == KIND_VEC` case above
|
||||
// for more details.
|
||||
if v_capacity >= new_cap && offset >= len {
|
||||
if v_capacity >= new_cap + offset {
|
||||
self.cap = new_cap;
|
||||
// no copy is necessary
|
||||
} else if v_capacity >= new_cap && offset >= len {
|
||||
// The capacity is sufficient, and copying is not too much
|
||||
// overhead: reclaim the buffer!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user