Skip to content

net: Buffers.WriteTo is prone to memory leaks #45163

Closed
@jwebb

Description

@jwebb

Buffers.WriteTo modifies its receiver (inside consume), leaving part of the backing array inaccessible. But it can still contain references that pin potentially large buffers into memory, so if the client code continues to hold the remainder of the slice for further use, it may have much higher memory consumption than expected.

The fix is simply to set (v*)[0] to nil before advancing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions