fix(memory): keep allocator ownership across Buffer.Reset#947
Merged
Conversation
fallintoplace
force-pushed
the
fix/buffer-reset-ownership
branch
from
July 15, 2026 03:51
5245076 to
ef84976
Compare
fallintoplace
force-pushed
the
fix/buffer-reset-ownership
branch
from
July 15, 2026 04:19
ef84976 to
67027be
Compare
zeroshade
approved these changes
Jul 15, 2026
zeroshade
left a comment
Member
There was a problem hiding this comment.
LGTM — verified the fix and its test coverage. Thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Buffer.Resetreplaced an allocator-owned slice directly. That leaked the old allocation and later causedReleaseto pass the caller supplied slice to the allocator.What changes are included in this PR?
When a buffer has an allocator, copy replacement data into allocator-owned storage and resize that storage without transferring ownership of the caller supplied slice. For shrinking resets, copying before resize also keeps resets from an overlapping slice safe if the allocator moves the allocation. Non-owning buffers keep the existing zero-copy behavior.
Are these changes tested?
Yes. Tests cover shrinking and growing from unrelated slices, source-slice independence, immediate release through
Reset(nil), final allocator accounting, and an overlapping reset with an allocator that always moves and invalidates the old allocation. Package, race-enabled, and lint checks pass.Are there any user-facing changes?
Resetting an allocator-backed buffer now copies the supplied data so ownership, growth, shrinking, overlapping resets, and release behavior remain valid.