diff options
author | apolcyn <apolcyn@google.com> | 2017-07-17 10:21:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-17 10:21:05 -0700 |
commit | da0c0ecb1a6db355ed5285a3a0c71d9d3b590e20 (patch) | |
tree | 304a1480c69cfcd512ee26519847aa23a3f800dd | |
parent | e313a68e1ffb42b784f75bab9a7023cb145d58cc (diff) | |
parent | 77349cd80a79283be2a88c02754aad4baf28f328 (diff) |
Merge pull request #11830 from apolcyn/fix_credential_compose_leaks_master
Fix ruby memory leaks when composing credentials, noticed with asan
-rw-r--r-- | src/ruby/ext/grpc/rb_call_credentials.c | 5 | ||||
-rw-r--r-- | src/ruby/ext/grpc/rb_channel_credentials.c | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/ruby/ext/grpc/rb_call_credentials.c b/src/ruby/ext/grpc/rb_call_credentials.c index 95e01a2c19..17083dd414 100644 --- a/src/ruby/ext/grpc/rb_call_credentials.c +++ b/src/ruby/ext/grpc/rb_call_credentials.c @@ -239,6 +239,7 @@ static VALUE grpc_rb_call_credentials_compose(int argc, VALUE *argv, VALUE self) { grpc_call_credentials *creds; grpc_call_credentials *other; + grpc_call_credentials *prev = NULL; VALUE mark; if (argc == 0) { return self; @@ -249,6 +250,10 @@ static VALUE grpc_rb_call_credentials_compose(int argc, VALUE *argv, rb_ary_push(mark, argv[i]); other = grpc_rb_get_wrapped_call_credentials(argv[i]); creds = grpc_composite_call_credentials_create(creds, other, NULL); + if (prev != NULL) { + grpc_call_credentials_release(prev); + } + prev = creds; } return grpc_rb_wrap_call_credentials(creds, mark); } diff --git a/src/ruby/ext/grpc/rb_channel_credentials.c b/src/ruby/ext/grpc/rb_channel_credentials.c index 07935a13dc..83601ca694 100644 --- a/src/ruby/ext/grpc/rb_channel_credentials.c +++ b/src/ruby/ext/grpc/rb_channel_credentials.c @@ -184,6 +184,7 @@ static VALUE grpc_rb_channel_credentials_compose(int argc, VALUE *argv, VALUE self) { grpc_channel_credentials *creds; grpc_call_credentials *other; + grpc_channel_credentials *prev = NULL; VALUE mark; if (argc == 0) { return self; @@ -195,6 +196,11 @@ static VALUE grpc_rb_channel_credentials_compose(int argc, VALUE *argv, rb_ary_push(mark, argv[i]); other = grpc_rb_get_wrapped_call_credentials(argv[i]); creds = grpc_composite_channel_credentials_create(creds, other, NULL); + if (prev != NULL) { + grpc_channel_credentials_release(prev); + } + prev = creds; + if (creds == NULL) { rb_raise(rb_eRuntimeError, "Failed to compose channel and call credentials"); |