Merge pull request #14132 from apolcyn/fix_benign_compression_options_mem_leak

Fix two ruby memory leaks when exceptions are raised
pull/14374/head
apolcyn 7 years ago committed by GitHub
commit f3431e5b21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/ruby/ext/grpc/rb_channel.c
  2. 16
      src/ruby/ext/grpc/rb_compression_options.c

@ -427,16 +427,15 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, VALUE mask,
parent_call = grpc_rb_get_wrapped_call(parent);
}
cq = grpc_completion_queue_create_for_pluck(NULL);
TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
if (wrapper->bg_wrapped == NULL) {
rb_raise(rb_eRuntimeError, "closed!");
return Qnil;
}
cq = grpc_completion_queue_create_for_pluck(NULL);
method_slice =
grpc_slice_from_copied_buffer(RSTRING_PTR(method), RSTRING_LEN(method));
call = grpc_channel_create_call(wrapper->bg_wrapped->channel, parent_call,
flags, cq, method_slice, host_slice_ptr,
grpc_rb_time_timeval(deadline,

@ -27,6 +27,8 @@
#include <grpc/impl/codegen/compression_types.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <string.h>
#include "rb_grpc.h"
@ -159,7 +161,6 @@ void grpc_rb_compression_options_algorithm_name_to_value_internal(
grpc_compression_algorithm* algorithm_value, VALUE algorithm_name) {
grpc_slice name_slice;
VALUE algorithm_name_as_string = Qnil;
char* tmp_str = NULL;
Check_Type(algorithm_name, T_SYMBOL);
@ -175,8 +176,17 @@ void grpc_rb_compression_options_algorithm_name_to_value_internal(
* the algorithm parse function
* in GRPC core. */
if (!grpc_compression_algorithm_parse(name_slice, algorithm_value)) {
tmp_str = grpc_slice_to_c_string(name_slice);
rb_raise(rb_eNameError, "Invalid compression algorithm name: %s", tmp_str);
char* name_slice_str = grpc_slice_to_c_string(name_slice);
char* error_message_str = NULL;
VALUE error_message_ruby_str = Qnil;
GPR_ASSERT(gpr_asprintf(&error_message_str,
"Invalid compression algorithm name: %s",
name_slice_str) != -1);
gpr_free(name_slice_str);
error_message_ruby_str =
rb_str_new(error_message_str, strlen(error_message_str));
gpr_free(error_message_str);
rb_raise(rb_eNameError, StringValueCStr(error_message_ruby_str));
}
grpc_slice_unref(name_slice);

Loading…
Cancel
Save