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_x509attr.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'ext/openssl/ossl_x509attr.c') diff --git a/ext/openssl/ossl_x509attr.c b/ext/openssl/ossl_x509attr.c index ee10dd8536..10e511d21d 100644 --- a/ext/openssl/ossl_x509attr.c +++ b/ext/openssl/ossl_x509attr.c @@ -10,11 +10,13 @@ */ #include "ossl.h" -#define WrapX509Attr(klass, obj, attr) do { \ +#define NewX509Attr(klass) \ + TypedData_Wrap_Struct((klass), &ossl_x509attr_type, 0) +#define SetX509Attr(obj, attr) do { \ if (!(attr)) { \ ossl_raise(rb_eRuntimeError, "ATTR wasn't initialized!"); \ } \ - (obj) = TypedData_Wrap_Struct((klass), &ossl_x509attr_type, (attr)); \ + RTYPEDDATA_DATA(obj) = (attr); \ } while (0) #define GetX509Attr(obj, attr) do { \ TypedData_Get_Struct((obj), X509_ATTRIBUTE, &ossl_x509attr_type, (attr)); \ @@ -56,6 +58,7 @@ ossl_x509attr_new(X509_ATTRIBUTE *attr) X509_ATTRIBUTE *new; VALUE obj; + obj = NewX509Attr(cX509Attr); if (!attr) { new = X509_ATTRIBUTE_new(); } else { @@ -64,7 +67,7 @@ ossl_x509attr_new(X509_ATTRIBUTE *attr) if (!new) { ossl_raise(eX509AttrError, NULL); } - WrapX509Attr(cX509Attr, obj, new); + SetX509Attr(obj, new); return obj; } @@ -91,9 +94,10 @@ ossl_x509attr_alloc(VALUE klass) X509_ATTRIBUTE *attr; VALUE obj; + obj = NewX509Attr(klass); if (!(attr = X509_ATTRIBUTE_new())) ossl_raise(eX509AttrError, NULL); - WrapX509Attr(klass, obj, attr); + SetX509Attr(obj, attr); return obj; } -- cgit v1.2.3