aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Alexander Polcyn <apolcyn@google.com>2018-01-22 19:37:15 -0800
committerGravatar Alexander Polcyn <apolcyn@google.com>2018-01-22 19:37:23 -0800
commit443165f88f9c99642e826e17292b3d101ccedf66 (patch)
tree52d3f9e1439347a83551d8616def3f8c5bdc56ab
parent6827d4473bc71601fdfc69cabe47a065109c416e (diff)
Fix two ruby memory leaks when exceptions are raised
-rw-r--r--src/ruby/ext/grpc/rb_channel.c3
-rw-r--r--src/ruby/ext/grpc/rb_compression_options.c16
2 files changed, 14 insertions, 5 deletions
diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c
index 1d11a53aa7..7f021784e5 100644
--- a/src/ruby/ext/grpc/rb_channel.c
+++ b/src/ruby/ext/grpc/rb_channel.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,
diff --git a/src/ruby/ext/grpc/rb_compression_options.c b/src/ruby/ext/grpc/rb_compression_options.c
index e24f20d2f9..7fdec2ee8b 100644
--- a/src/ruby/ext/grpc/rb_compression_options.c
+++ b/src/ruby/ext/grpc/rb_compression_options.c
@@ -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);