mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-08 00:00:26 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7249149a9 | ||
|
|
d6e1999d97 |
@@ -1,3 +1,9 @@
|
||||
# 1.2.1 (July 30, 2022)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix unbounded memory growth when using `reserve` (#560)
|
||||
|
||||
# 1.2.0 (July 19, 2022)
|
||||
|
||||
### Added
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ name = "bytes"
|
||||
# When releasing to crates.io:
|
||||
# - Update CHANGELOG.md.
|
||||
# - Create "v1.x.y" git tag.
|
||||
version = "1.2.0"
|
||||
version = "1.2.1"
|
||||
license = "MIT"
|
||||
authors = [
|
||||
"Carl Lerche <[email protected]>",
|
||||
|
||||
+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!
|
||||
|
||||
|
||||
@@ -515,6 +515,34 @@ fn reserve_in_arc_unique_doubles() {
|
||||
assert_eq!(2000, bytes.capacity());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reserve_in_arc_unique_does_not_overallocate_after_split() {
|
||||
let mut bytes = BytesMut::from(LONG);
|
||||
let orig_capacity = bytes.capacity();
|
||||
drop(bytes.split_off(LONG.len() / 2));
|
||||
|
||||
// now bytes is Arc and refcount == 1
|
||||
|
||||
let new_capacity = bytes.capacity();
|
||||
bytes.reserve(orig_capacity - new_capacity);
|
||||
assert_eq!(bytes.capacity(), orig_capacity);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reserve_in_arc_unique_does_not_overallocate_after_multiple_splits() {
|
||||
let mut bytes = BytesMut::from(LONG);
|
||||
let orig_capacity = bytes.capacity();
|
||||
for _ in 0..10 {
|
||||
drop(bytes.split_off(LONG.len() / 2));
|
||||
|
||||
// now bytes is Arc and refcount == 1
|
||||
|
||||
let new_capacity = bytes.capacity();
|
||||
bytes.reserve(orig_capacity - new_capacity);
|
||||
}
|
||||
assert_eq!(bytes.capacity(), orig_capacity);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reserve_in_arc_nonunique_does_not_overallocate() {
|
||||
let mut bytes = BytesMut::with_capacity(1000);
|
||||
|
||||
Reference in New Issue
Block a user