Use a drop guard to prevent leaving a dangling reference in internals::serialize::id::run_as_context #203
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.
After reading about the recent improvements to Miri, I tried using it to run Legion's tests. Most of them succeed, but
internals::serialize::test::serialize_bincode
andinternals::serialize::test::serialize_json
both panic for reasons I haven't looked into, and because they run in the same thread, the second one finds a dangling pointer and triggers an error in Miri.This pull request fixes that problem, leaving both test results as panics rather than undefined behavior. The comment suggested using
catch_unwind
for this, but I used the more common and probably more efficient pattern of a guard struct with aDrop
implementation that cleans up. I also added a small test to make sure Miri always has the opportunity to catch this bug, since it was essentially a coincidence that it was caught this time.