diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-06-05 07:48:27 -0700 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-06-05 07:48:27 -0700 |
commit | 4beef422642144fdfbf0afa892ebef659d156d00 (patch) | |
tree | 67744d9c655eb705627390366a17a402e2a7d81f | |
parent | b73856916ac97efa9ec8091ba339e82e52b5a694 (diff) |
Clarify ownership
-rw-r--r-- | include/grpc++/byte_buffer.h | 4 | ||||
-rw-r--r-- | include/grpc++/impl/call.h | 7 | ||||
-rw-r--r-- | include/grpc++/impl/proto_utils.h | 3 |
3 files changed, 9 insertions, 5 deletions
diff --git a/include/grpc++/byte_buffer.h b/include/grpc++/byte_buffer.h index 80b3397a2d..5f419764a5 100644 --- a/include/grpc++/byte_buffer.h +++ b/include/grpc++/byte_buffer.h @@ -90,8 +90,10 @@ class SerializationTraits<ByteBuffer, void> { dest->set_buffer(byte_buffer); return Status::OK; } - static bool Serialize(const ByteBuffer& source, grpc_byte_buffer** buffer) { + static bool Serialize(const ByteBuffer& source, grpc_byte_buffer** buffer, + bool* own_buffer) { *buffer = source.buffer(); + *own_buffer = false; return true; } }; diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h index eb8027cef5..43d3805827 100644 --- a/include/grpc++/impl/call.h +++ b/include/grpc++/impl/call.h @@ -95,11 +95,11 @@ class CallOpSendInitialMetadata { class CallOpSendMessage { public: - CallOpSendMessage() : send_buf_(nullptr) {} + CallOpSendMessage() : send_buf_(nullptr), own_buf_(false) {} template <class M> bool SendMessage(const M& message) GRPC_MUST_USE_RESULT { - return SerializationTraits<M>::Serialize(message, &send_buf_); + return SerializationTraits<M>::Serialize(message, &send_buf_, &own_buf_); } protected: @@ -110,11 +110,12 @@ class CallOpSendMessage { op->data.send_message = send_buf_; } void FinishOp(void* tag, bool* status, int max_message_size) { - grpc_byte_buffer_destroy(send_buf_); + if (own_buf_) grpc_byte_buffer_destroy(send_buf_); } private: grpc_byte_buffer* send_buf_; + bool own_buf_; }; template <class R> diff --git a/include/grpc++/impl/proto_utils.h b/include/grpc++/impl/proto_utils.h index ee19859198..bf82f2b23d 100644 --- a/include/grpc++/impl/proto_utils.h +++ b/include/grpc++/impl/proto_utils.h @@ -59,7 +59,8 @@ class SerializationTraits<T, typename std::enable_if<std::is_base_of< grpc::protobuf::Message, T>::value>::type> { public: static bool Serialize(const grpc::protobuf::Message& msg, - grpc_byte_buffer** buffer) { + grpc_byte_buffer** buffer, bool* own_buffer) { + *own_buffer = true; return SerializeProto(msg, buffer); } static Status Deserialize(grpc_byte_buffer* buffer, |