aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ruby/ext/grpc/rb_byte_buffer.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/ruby/ext/grpc/rb_byte_buffer.c b/src/ruby/ext/grpc/rb_byte_buffer.c
index 52523b8319..9b617e13d3 100644
--- a/src/ruby/ext/grpc/rb_byte_buffer.c
+++ b/src/ruby/ext/grpc/rb_byte_buffer.c
@@ -50,24 +50,18 @@ grpc_byte_buffer* grpc_rb_s_to_byte_buffer(char *string, size_t length) {
}
VALUE grpc_rb_byte_buffer_to_s(grpc_byte_buffer *buffer) {
- size_t length = 0;
- char *string = NULL;
VALUE rb_string;
- size_t offset = 0;
grpc_byte_buffer_reader reader;
gpr_slice next;
if (buffer == NULL) {
return Qnil;
}
- length = grpc_byte_buffer_length(buffer);
- string = xmalloc(length + 1);
+ rb_string = rb_str_buf_new(grpc_byte_buffer_length(buffer));
grpc_byte_buffer_reader_init(&reader, buffer);
while (grpc_byte_buffer_reader_next(&reader, &next) != 0) {
- memcpy(string + offset, GPR_SLICE_START_PTR(next), GPR_SLICE_LENGTH(next));
- offset += GPR_SLICE_LENGTH(next);
+ rb_str_cat(rb_string, (const char *) GPR_SLICE_START_PTR(next),
+ GPR_SLICE_LENGTH(next));
gpr_slice_unref(next);
}
- rb_string = rb_str_new(string, length);
- xfree(string);
return rb_string;
}