From e672dabfea5f851e5aa850e178e3d3ceb52777ec Mon Sep 17 00:00:00 2001 From: xuyatian Date: Mon, 18 Oct 2021 11:24:52 -0700 Subject: [PATCH] [C++] Fix memory leak when using grpc (#6896) (#6897) --- include/flatbuffers/grpc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/flatbuffers/grpc.h b/include/flatbuffers/grpc.h index 2b8f24787..5d15bc51c 100644 --- a/include/flatbuffers/grpc.h +++ b/include/flatbuffers/grpc.h @@ -276,10 +276,12 @@ template class SerializationTraits> { Slice slice; if (!buf->TrySingleSlice(&slice).ok()) { if (!buf->DumpToSingleSlice(&slice).ok()) { + buf->Clear(); return ::grpc::Status(::grpc::StatusCode::INTERNAL, "No payload"); } } *msg = flatbuffers::grpc::Message(slice); + buf->Clear(); #if FLATBUFFERS_GRPC_DISABLE_AUTO_VERIFICATION return ::grpc::Status::OK; #else