Repository navigation
[C++] Make grpc::MessageBuilder::Release() hand over its slice - #9513
Open
aaronjmars wants to merge 1 commit into
Open
aaronjmars wants to merge 1 commit into
aaronjmars wants to merge 1 commit into
Conversation
MessageBuilder inherited FlatBufferBuilder::Release(), which returns a DetachedBuffer that still points into the grpc::Slice held by the builder's SliceAllocator. Reusing the builder then hit an assert in SliceAllocator::allocate, and destroying or move-assigning it freed the memory the DetachedBuffer was still using. Add a Release() override that moves the slice into a new SliceAllocator owned by the DetachedBuffer, and enable the two reuse-after-Release tests that were disabled because of this.
This branch has not been deployed
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.
flatbuffers::grpc::MessageBuilderinheritsFlatBufferBuilder::Release(). TheDetachedBufferit returns points into thegrpc::Slicethat is still held by the builder'sSliceAllocator, so:Release()tripsFLATBUFFERS_ASSERT(slice_.size() == 0)inSliceAllocator::allocate(or, with asserts off, replaces the slice the detached buffer is still reading from);DetachedBufferis alive frees the memory under it.This adds
MessageBuilder::Release(), which uses the existing three-argumentReleaseRaw()to move the slice into a newSliceAllocatorand returns aDetachedBufferthat owns that allocator. The buffer then frees the slice itself when it goes away, and the builder can be reused like afterReleaseRaw()orReleaseMessage().grpc/tests/message_builder_test.cppalready hadbuilder_reusable_after_release_testandbuilder_reusable_after_release_and_move_assign_test, disabled with FIXME notes describing exactly these asserts. This change enables them and removes the notes.Testing: built
message_builder_tests()fromgrpc/tests/message_builder_test.cppwith clang and AddressSanitizer against gRPC 1.85. With the change all tests pass and ASan is clean; without the header change the newly enabled tests fail with theslice_.size() == 0assert.