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_x509req.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_x509req.c')
-rw-r--r-- | ext/openssl/ossl_x509req.c | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/ext/openssl/ossl_x509req.c b/ext/openssl/ossl_x509req.c index d2619971..220d2f40 100644 --- a/ext/openssl/ossl_x509req.c +++ b/ext/openssl/ossl_x509req.c @@ -160,8 +160,6 @@ ossl_x509req_to_pem(VALUE self) { X509_REQ *req; BIO *out; - BUF_MEM *buf; - VALUE str; GetX509Req(self, req); if (!(out = BIO_new(BIO_s_mem()))) { @@ -171,11 +169,8 @@ ossl_x509req_to_pem(VALUE self) BIO_free(out); ossl_raise(eX509ReqError, NULL); } - BIO_get_mem_ptr(out, &buf); - str = rb_str_new(buf->data, buf->length); - BIO_free(out); - return str; + return ossl_membio2str(out); } static VALUE @@ -203,8 +198,6 @@ ossl_x509req_to_text(VALUE self) { X509_REQ *req; BIO *out; - BUF_MEM *buf; - VALUE str; GetX509Req(self, req); if (!(out = BIO_new(BIO_s_mem()))) { @@ -214,11 +207,8 @@ ossl_x509req_to_text(VALUE self) BIO_free(out); ossl_raise(eX509ReqError, NULL); } - BIO_get_mem_ptr(out, &buf); - str = rb_str_new(buf->data, buf->length); - BIO_free(out); - return str; + return ossl_membio2str(out); } #if 0 @@ -304,8 +294,6 @@ ossl_x509req_get_signature_algorithm(VALUE self) X509_REQ *req; const X509_ALGOR *alg; BIO *out; - BUF_MEM *buf; - VALUE str; GetX509Req(self, req); @@ -317,10 +305,8 @@ ossl_x509req_get_signature_algorithm(VALUE self) BIO_free(out); ossl_raise(eX509ReqError, NULL); } - BIO_get_mem_ptr(out, &buf); - str = rb_str_new(buf->data, buf->length); - BIO_free(out); - return str; + + return ossl_membio2str(out); } static VALUE |