Merge pull request #4219 from w4-sjcho/master

Fixes memory leaks described in #4211
pull/4225/head
Michael Lumish 9 years ago
commit cf42611b39
  1. 1
      src/node/ext/byte_buffer.cc
  2. 13
      src/node/ext/call.cc

@ -77,6 +77,7 @@ Local<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) {
while (grpc_byte_buffer_reader_next(&reader, &next) != 0) { while (grpc_byte_buffer_reader_next(&reader, &next) != 0) {
memcpy(result + offset, GPR_SLICE_START_PTR(next), GPR_SLICE_LENGTH(next)); memcpy(result + offset, GPR_SLICE_START_PTR(next), GPR_SLICE_LENGTH(next));
offset += GPR_SLICE_LENGTH(next); offset += GPR_SLICE_LENGTH(next);
gpr_slice_unref(next);
} }
return scope.Escape(MakeFastBuffer( return scope.Escape(MakeFastBuffer(
Nan::NewBuffer(result, length).ToLocalChecked())); Nan::NewBuffer(result, length).ToLocalChecked()));

@ -234,6 +234,14 @@ class SendMetadataOp : public Op {
class SendMessageOp : public Op { class SendMessageOp : public Op {
public: public:
SendMessageOp() {
send_message = NULL;
}
~SendMessageOp() {
if (send_message != NULL) {
grpc_byte_buffer_destroy(send_message);
}
}
Local<Value> GetNodeValue() const { Local<Value> GetNodeValue() const {
EscapableHandleScope scope; EscapableHandleScope scope;
return scope.Escape(Nan::True()); return scope.Escape(Nan::True());
@ -253,7 +261,8 @@ class SendMessageOp : public Op {
out->flags = maybe_flag.FromMaybe(0) & GRPC_WRITE_USED_MASK; 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); PersistentValue *handle = new PersistentValue(value);
resources->handles.push_back(unique_ptr<PersistentValue>(handle)); resources->handles.push_back(unique_ptr<PersistentValue>(handle));
return true; return true;
@ -262,6 +271,8 @@ class SendMessageOp : public Op {
std::string GetTypeString() const { std::string GetTypeString() const {
return "send_message"; return "send_message";
} }
private:
grpc_byte_buffer *send_message;
}; };
class SendClientCloseOp : public Op { class SendClientCloseOp : public Op {

Loading…
Cancel
Save