Advance list.first before freeing the chunk in cleanup_impl - #25
Closed
tooson9010-spec wants to merge 1 commit into
Closed
tooson9010-spec wants to merge 1 commit into
tooson9010-spec wants to merge 1 commit into
Conversation
`free_chunk` runs each element's `Drop`, which may unwind. When it does, `list.first` still points at the chunk that was just freed, and `Drop for EventQueue` walks the list from there and frees it again. Swapping the two statements retires the chunk first. `free_chunk` does not read `list.first`, so the order is free. Elements left in the chunk that panicked are leaked, which is safe. Adds a test: without this change it counts 13 drops for 12 elements.
Owner
|
"Project is deprecated in favor of chute." as stated in the first line of readme. |
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.
Summary
cleanup_implfrees a chunk withfree_chunkand only then advanceslist.first.free_chunkruns each element'sDrop, which may unwind. Whenit does,
list.firststill points at the chunk that was just freed, andDrop for EventQueuewalks the list from there and frees it again. Adouble-free (CWE-415) reachable from safe Rust.
Two of the paths into
cleanup_implneed no explicit cleanup call. WithCleanupMode::OnNewChunk(spmc default)add_chunkcalls it on every chunkboundary, so
pushis enough. WithCleanupMode::OnChunkRead(mpmc default)it runs when an
Iteris dropped. The others arecleanup,clearandtruncate_front.Fix
Swap the two statements so the chunk is retired before it is freed.
free_chunkreadsstart_position,total_capacityandfree_chunk, notlist.first. Elements left in the chunk that panicked are leaked, which issafe.
The default and
double_bufferingpaths both go throughDynamicChunk::recycle, so one change covers them.Verification
Added a test to
src/event_queue/test.rs: 12 elements across chunks of 4, thefirst panics on drop,
cleanup()undercatch_unwind. Without the change itcounts 13 drops for 12 elements; with it, 9.
Existing tests pass. Confirmed on 0.4.3.