From c4c3bff8140282127e34ed1e2d83082866db2d1f Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Thu, 29 Jan 2015 13:50:56 -0800 Subject: [PATCH] Fixed memory leak in PHP byte buffer creation --- src/php/ext/grpc/byte_buffer.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/php/ext/grpc/byte_buffer.c b/src/php/ext/grpc/byte_buffer.c index e2f63e3413b..29d6fa03579 100644 --- a/src/php/ext/grpc/byte_buffer.c +++ b/src/php/ext/grpc/byte_buffer.c @@ -16,9 +16,10 @@ #include "grpc/support/slice.h" grpc_byte_buffer *string_to_byte_buffer(char *string, size_t length) { - gpr_slice slice = gpr_slice_malloc(length); - memcpy(GPR_SLICE_START_PTR(slice), string, length); - return grpc_byte_buffer_create(&slice, 1); + gpr_slice slice = gpr_slice_from_copied_buffer(string, length); + grpc_byte_buffer *buffer = grpc_byte_buffer_create(&slice, 1); + gpr_slice_unref(slice); + return buffer; } void byte_buffer_to_string(grpc_byte_buffer *buffer, char **out_string,