Skip to content

Commit

Permalink
Merge pull request grpc#6719 from murgatroid99/node_compressed_read_fix
Browse files Browse the repository at this point in the history
Make Node not segfault when it receives a compressed message
  • Loading branch information
jtattermusch committed Jun 1, 2016
2 parents f7d95c3 + c04f7b1 commit be0456c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/node/ext/byte_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,13 @@ Local<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) {
if (buffer == NULL) {
return scope.Escape(Nan::Null());
}
size_t length = grpc_byte_buffer_length(buffer);
char *result = new char[length];
size_t offset = 0;
grpc_byte_buffer_reader reader;
grpc_byte_buffer_reader_init(&reader, buffer);
gpr_slice next;
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);
}
gpr_slice slice = grpc_byte_buffer_reader_readall(&reader);
size_t length = GPR_SLICE_LENGTH(slice);
char *result = new char[length];
memcpy(result, GPR_SLICE_START_PTR(slice), length);
gpr_slice_unref(slice);
return scope.Escape(MakeFastBuffer(
Nan::NewBuffer(result, length, delete_buffer, NULL).ToLocalChecked()));
}
Expand Down

0 comments on commit be0456c

Please sign in to comment.