Repository navigation
Fix allocator leak when consuming an unallocated table - #751
Merged
clarfonthey merged 1 commit intoSep 24, 2026
Merged
Conversation
Contributor
Author
|
CI is currently failing because of allocator_api being partially stabilized and this project not pinning a nightly toolchain, nothing in my PR. I blame @nia-e :) |
Contributor
|
I'll take a look at fixing CI on another branch; you can rebase on that once I fix it. I think there are a few issues at play. |
Contributor
|
Yeah, okay, you were right that it's just the |
`RawTable::into_allocation` returned `None` for the empty singleton and then called `mem::forget(self)`, which also forgot the allocator. Any allocator with a non-trivial `Drop` (e.g. one holding an `Rc`/`Arc`) was leaked when an unallocated `HashMap`/`HashSet`/`HashTable` was consumed via `into_iter` or `into_par_iter`. Move the allocator out unconditionally so it is dropped when there is no allocation to hand back.
xacrimon
force-pushed
the
fix-empty-into-iter-alloc-leak
branch
from
September 24, 2026 11:11
730e9a2 to
1e87e1f
Compare
Contributor
Author
|
:) rebased, I'd consider this ready for review now. thanks! |
Contributor
|
Yeah, this looks very reasonable to me. Thank you! |
Contributor
Author
|
any chance we might get a point release reasonably soon? |
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.
RawTable::into_allocationreturnsNonewhen the table is the empty singleton (it never allocated), and then callsmem::forget(self). The allocator is only moved out on the allocated path, so on the empty path it is forgotten along with the table.Any allocator with a non-trivial
Dropis leaked whenever an unallocatedHashMap/HashSet/HashTableis consumed viainto_iter(orinto_par_iter, which goes through the same function). For example, an allocator holding anRc/Arcloses one strong count per consumed empty table.#439 fixed the same leak for tables that had allocated, but the non-allocated path still does not drop the allocator.
Fix
Wrap
selfinManuallyDropand read the allocator out unconditionally. It is returned alongside the allocation when there is one, and dropped otherwise.Testing
test_hashmap_into_iter_unallocated_drops_allocator, which fails before this change (allocator refcount stays at 1) and passes after.cargo test --all-targets,cargo test --features rayon,serde,raw-entry, andcargo +nightly test --features nightly,rayonpass.cargo miri test --lib into_iterpasses with leak checking enabled.