Destroy handle_ in ~KafkaHandleBase body to fix use-after-dtor - #324
Open
makxenov wants to merge 1 commit into
Open
Destroy handle_ in ~KafkaHandleBase body to fix use-after-dtor#324makxenov wants to merge 1 commit into
makxenov wants to merge 1 commit into
Conversation
handle_ is a unique_ptr whose HandleDeleter reads destroy_flags_ back through the owning KafkaHandleBase when it runs. With a defaulted destructor, member destruction is member-wise: the trivial fields (including destroy_flags_) are destroyed before handle_, so the deleter reads them afterwards. Under MSan -fsanitize-memory-use-after-dtor that destruction poisons the fields, turning the read into a use-after-destructor. Reset handle_ explicitly in the destructor body, while the object -- and destroy_flags_ -- is still fully alive.
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.
handle_is aunique_ptrwhoseHandleDeleterreadsdestroy_flags_ backthrough the owningKafkaHandleBasewhen it runs. With a defaulted destructor, member destruction is member-wise: the trivial fields (includingdestroy_flags_) are destroyed beforehandle_, so the deleter reads them afterwards. Under MSan -fsanitize-memory-use-after-dtor that destruction poisons the fields, turning the read into a use-after-destructor.Reset
handle_explicitly in the destructor body, while the object -- anddestroy_flags_-- is still fully alive.