summaryrefslogtreecommitdiff
path: root/ext/openssl/ossl_digest.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-29 05:55:02 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-29 05:55:02 +0000
commit451fe269e5ab1270a53ac7bdeceabe47fd431f95 (patch)
treeed014c958a0f622db02af64186def2c70e4c00ba /ext/openssl/ossl_digest.c
parent5924f9a684ace630d3658a0d6e52270e3686ca9f (diff)
openssl: wrapper object before alloc
* ext/openssl: make wrapper objects before allocating structs to get rid of potential memory leaks. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_digest.c')
-rw-r--r--ext/openssl/ossl_digest.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/ext/openssl/ossl_digest.c b/ext/openssl/ossl_digest.c
index 83dbc34..0ed12c5 100644
--- a/ext/openssl/ossl_digest.c
+++ b/ext/openssl/ossl_digest.c
@@ -95,13 +95,11 @@ ossl_digest_new(const EVP_MD *md)
static VALUE
ossl_digest_alloc(VALUE klass)
{
- EVP_MD_CTX *ctx;
- VALUE obj;
-
- ctx = EVP_MD_CTX_create();
+ VALUE obj = TypedData_Wrap_Struct(klass, &ossl_digest_type, 0);
+ EVP_MD_CTX *ctx = EVP_MD_CTX_create();
if (ctx == NULL)
ossl_raise(rb_eRuntimeError, "EVP_MD_CTX_create() failed");
- obj = TypedData_Wrap_Struct(klass, &ossl_digest_type, ctx);
+ RTYPEDDATA_DATA(obj) = ctx;
return obj;
}