diff --git a/src/node/ext/byte_buffer.cc b/src/node/ext/byte_buffer.cc index e1786ddba7e..c306292c04c 100644 --- a/src/node/ext/byte_buffer.cc +++ b/src/node/ext/byte_buffer.cc @@ -77,6 +77,7 @@ Local ByteBufferToBuffer(grpc_byte_buffer *buffer) { while (grpc_byte_buffer_reader_next(&reader, &next) != 0) { memcpy(result + offset, GPR_SLICE_START_PTR(next), GPR_SLICE_LENGTH(next)); offset += GPR_SLICE_LENGTH(next); + gpr_slice_unref(next); } return scope.Escape(MakeFastBuffer( Nan::NewBuffer(result, length).ToLocalChecked())); diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index a98ae85427f..c0e2b0f0e8f 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.cc @@ -234,6 +234,14 @@ class SendMetadataOp : public Op { class SendMessageOp : public Op { public: + SendMessageOp() { + send_message = NULL; + } + ~SendMessageOp() { + if (send_message != NULL) { + grpc_byte_buffer_destroy(send_message); + } + } Local GetNodeValue() const { EscapableHandleScope scope; return scope.Escape(Nan::True()); @@ -253,7 +261,8 @@ class SendMessageOp : public Op { out->flags = maybe_flag.FromMaybe(0) & GRPC_WRITE_USED_MASK; } } - out->data.send_message = BufferToByteBuffer(value); + send_message = BufferToByteBuffer(value); + out->data.send_message = send_message; PersistentValue *handle = new PersistentValue(value); resources->handles.push_back(unique_ptr(handle)); return true; @@ -262,6 +271,8 @@ class SendMessageOp : public Op { std::string GetTypeString() const { return "send_message"; } + private: + grpc_byte_buffer *send_message; }; class SendClientCloseOp : public Op {