fix(driver): memory leaks on drop#769
Merged
Berrysoft merged 2 commits intocompio-rs:masterfrom Mar 17, 2026
Merged
Conversation
7375916 to
8456b53
Compare
Member
|
Thanks for the PR. |
Member
|
For 3, there might be ops still operating, referencing this bufing. Therefore, it's not safe to drop the buffers before releasing it. |
8456b53 to
dd0bbc0
Compare
Contributor
Author
|
Reverted 2 and 3. Please give it a second look 🙇♂️ |
Berrysoft
reviewed
Mar 15, 2026
Berrysoft
approved these changes
Mar 16, 2026
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.
I used asan to look for leaks in compio-driver and found 3 sources of memory leaks in
compio-driverwhen the driver or its resources are dropped without all operations completing. Found via AddressSanitizer + LeakSanitizer (-Zsanitizer=addresswith-Zbuild-std).Before: 12,952 bytes leaked in 18 allocations across the test suite
After: 0 bytes leaked
Changes
1. io_uring
Driver— in-flight key tracking +Dropimplpush_raw_with_keycallskey.into_raw()to leak theThinCell<RawOp>allocation as au64user_data into the io_uring submission queue. On completion,ErasedKey::from_raw()reconstructs ownership. But if theDriverdrops before all completions arrive (which happens on every normal process exit), the raw pointers are never reconstructed and the allocations leak.Fix: Track in-flight raw pointers in a
HashSet<usize>. Remove on completion. InDrop, drain the completion queue, then free any remaining tracked keys viaErasedKey::from_raw().I've also committed the asan script I used.
Edit: These have been reverted
2.FrozenKey— missingDropimpl~~
FrozenKeywrapsManuallyDrop<ErasedKey>and has noDropimpl. It's used inpush_blockingto send operations to the thread pool. If the thread pool drops the closure without running it (e.g., on shutdown), the innerErasedKeyleaks.Fix: Add
impl Drop for FrozenKeythat drops the innerErasedKey. Modifyinto_inner()to wrapselfinManuallyDropfirst, preventing double-drop on the normal (non-leak) path.~~~~ 3.
BufferPoolInner—IoUringBufRingleaks on drop~~IoUringBufRinginternally stores its mmap region and backing buffers inManuallyDropfields. It requires an explicitrelease()call (which unregisters from io_uring) to free them. If aBufferPoolis dropped without callingrelease_buffer_pool, the mmap and bufferVecs leak.Fix: Wrapbuf_ringinManuallyDropinsideBufferPoolInnerand add aDropimpl that callsIoUringBufRing::drop()(the crate's provided unsafe cleanup function that frees memory without unregistering). Updateinto_inner()to take the ring out andmem::forgetthe wrapper to prevent double-free when the caller intends to callrelease().