From 451fe269e5ab1270a53ac7bdeceabe47fd431f95 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 29 May 2015 05:55:02 +0000 Subject: 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 --- ext/openssl/ossl_digest.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'ext/openssl/ossl_digest.c') diff --git a/ext/openssl/ossl_digest.c b/ext/openssl/ossl_digest.c index 83dbc34e3e..0ed12c5a56 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; } -- cgit v1.2.3