diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-08-24 21:57:52 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-10-03 15:02:15 +0900 |
commit | cf2d4f43a98bdc37224460a0b1851a0dc7ced2e8 (patch) | |
tree | 82755c6e3a29e6359891cc4837977ee2f3155d94 /ext/openssl/ossl_ssl_session.c | |
parent | 0954e9316fdfdda920561ea362f235c10ceebc04 (diff) | |
download | ruby-openssl-cf2d4f43a98bdc37224460a0b1851a0dc7ced2e8.tar.gz |
Avoid memory leak on rb_str_new()
Use ossl_membio2str() to convert a mem BIO to Ruby String. This fixes
possible memory leak on rb_str_new() failure, and also reduces code.
Diffstat (limited to 'ext/openssl/ossl_ssl_session.c')
-rw-r--r-- | ext/openssl/ossl_ssl_session.c | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/ext/openssl/ossl_ssl_session.c b/ext/openssl/ossl_ssl_session.c index fb7c0fb6..699a301b 100644 --- a/ext/openssl/ossl_ssl_session.c +++ b/ext/openssl/ossl_ssl_session.c @@ -270,9 +270,6 @@ static VALUE ossl_ssl_session_to_pem(VALUE self) { SSL_SESSION *ctx; BIO *out; - BUF_MEM *buf; - VALUE str; - int i; GetSSLSession(self, ctx); @@ -280,16 +277,13 @@ static VALUE ossl_ssl_session_to_pem(VALUE self) ossl_raise(eSSLSession, "BIO_s_mem()"); } - if (!(i=PEM_write_bio_SSL_SESSION(out, ctx))) { + if (!PEM_write_bio_SSL_SESSION(out, ctx)) { BIO_free(out); ossl_raise(eSSLSession, "SSL_SESSION_print()"); } - BIO_get_mem_ptr(out, &buf); - str = rb_str_new(buf->data, buf->length); - BIO_free(out); - return str; + return ossl_membio2str(out); } @@ -303,8 +297,6 @@ static VALUE ossl_ssl_session_to_text(VALUE self) { SSL_SESSION *ctx; BIO *out; - BUF_MEM *buf; - VALUE str; GetSSLSession(self, ctx); @@ -317,11 +309,7 @@ static VALUE ossl_ssl_session_to_text(VALUE self) ossl_raise(eSSLSession, "SSL_SESSION_print()"); } - BIO_get_mem_ptr(out, &buf); - str = rb_str_new(buf->data, buf->length); - BIO_free(out); - - return str; + return ossl_membio2str(out); } |