Repository navigation
Fix sparse FlatMap swap thumbnail reset - #3619
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix corrects storage ownership, and regression tests cover both reported failure scenarios.
No open issues 🎉
What changed in this PR
Fixes SparseFlatMap::swap() so the moved-from map no longer retains a thumbnail pointer to transferred storage.
Changes:
- Reset the moved-from thumbnail to its default storage.
- Add regression tests for map reuse and destruction of the transferred storage’s owner.
| File | Description |
|---|---|
| test/flat_map_unittest.cpp | Adds regression coverage for sparse-map swaps. |
| src/butil/containers/flat_map_inl.h | Corrects the moved-from thumbnail reset. |
Review effort: Balanced
Contributor
|
LGTM |
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.
What problem does this PR solve?
Issue Number: resolve
Problem Summary:
FlatMap::swap()does not fully reset the moved-from object when swapping adefault-initialized
SparseFlatMapwith a dynamically initialized one.After transferring the dynamic buckets to the default map, the moved-from map
resets
_bucketsbut mistakenly assigns_thumbnailto itself. Its thumbnailtherefore still points to the transferred dynamic storage. Once the new owner
is destroyed, later operations on the moved-from map can access freed memory.
What is changed and the side effects?
Changed:
_thumbnailto_default_thumbnailtogetherwith
_buckets.SparseFlatMapinstances, including use after the temporary owner is destroyed.
Side effects:
Performance effects:
Breaking backward compatibility:
Check List: