Skip to content

Fix memory leak in alloc_try_with and try_alloc_try_with - #322

Open
Shnatsel wants to merge 3 commits into
fitzgen:mainfrom
Shnatsel:memory-leak
Open

Fix memory leak in alloc_try_with and try_alloc_try_with#322
Shnatsel wants to merge 3 commits into
fitzgen:mainfrom
Shnatsel:memory-leak

Conversation

@Shnatsel

Copy link
Copy Markdown

When allocating a new chunk, these functions erroneously mark it as full. The pointers are set to the start of the chunk, but the bump allocator grows downwards, so the space in the newly allocated chunk appears to be exhausted.

This doc comment might have been the source of the error, since it's not entirely clear what "start" and "end" means for an allocator growing downwards in the address space:

bumpalo/src/lib.rs

Lines 301 to 304 in 657caf8

struct ChunkFooter {
// Pointer to the start of this chunk allocation. This footer is always at
// the end of the chunk.
data: NonNull<u8>,

The issue was identified by Claude Opus 4.7 as part of a memory safety audit. It turned up no security issues as of commit 657caf8.

Shnatsel and others added 3 commits April 27, 2026 12:28
…k rewind

When `alloc_try_with` / `try_alloc_try_with` allocates a new chunk for the
`Result<T, E>` and the closure returns `Err`, the rewind logic sets the
bump pointer to `footer.data` (the LOWEST address of the chunk). Since the
bump pointer grows downward, this marks the chunk as completely full
instead of empty, leaking the entire chunk until the bump is reset.

Co-Authored-By: Claude <noreply@anthropic.com>
@Shnatsel

Copy link
Copy Markdown
Author

Ah, it seems I've reinvented #315

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant