Skip to content

reserve_inner over allocates which can lead to a OOM conidition #559

Closed
@schultetwin1

Description

@schultetwin1

Summary

reseve_inner will double the size of the underlying shared vector instead of just extending the BytesMut buffer in place if a call to BytesMut::reserve would fit inside the current allocated shared buffer. If this happens repeatedly you will eventually attempt to allocate a buffer that is too large.

Repro

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));
    let new_capacity = bytes.capacity();
    bytes.reserve(orig_capacity - new_capacity);
    assert_eq!(bytes.capacity(), orig_capacity);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions