summaryrefslogtreecommitdiff
path: root/ext/openssl/ossl_x509ext.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_x509ext.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_x509ext.c')
-rw-r--r--ext/openssl/ossl_x509ext.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/ext/openssl/ossl_x509ext.c b/ext/openssl/ossl_x509ext.c
index f74bd29..1e65f2b 100644
--- a/ext/openssl/ossl_x509ext.c
+++ b/ext/openssl/ossl_x509ext.c
@@ -10,11 +10,13 @@
*/
#include "ossl.h"
-#define WrapX509Ext(klass, obj, ext) do { \
+#define NewX509Ext(klass) \
+ TypedData_Wrap_Struct((klass), &ossl_x509ext_type, 0)
+#define SetX509Ext(obj, ext) do { \
if (!(ext)) { \
ossl_raise(rb_eRuntimeError, "EXT wasn't initialized!"); \
} \
- (obj) = TypedData_Wrap_Struct((klass), &ossl_x509ext_type, (ext)); \
+ RTYPEDDATA_DATA(obj) = (ext); \
} while (0)
#define GetX509Ext(obj, ext) do { \
TypedData_Get_Struct((obj), X509_EXTENSION, &ossl_x509ext_type, (ext)); \
@@ -27,10 +29,11 @@
GetX509Ext((obj), (ext)); \
} while (0)
#define MakeX509ExtFactory(klass, obj, ctx) do { \
+ (obj) = TypedData_Wrap_Struct((klass), &ossl_x509extfactory_type, 0); \
if (!((ctx) = OPENSSL_malloc(sizeof(X509V3_CTX)))) \
ossl_raise(rb_eRuntimeError, "CTX wasn't allocated!"); \
X509V3_set_ctx((ctx), NULL, NULL, NULL, NULL, 0); \
- (obj) = TypedData_Wrap_Struct((klass), &ossl_x509extfactory_type, (ctx)); \
+ RTYPEDDATA_DATA(obj) = (ctx); \
} while (0)
#define GetX509ExtFactory(obj, ctx) do { \
TypedData_Get_Struct((obj), X509V3_CTX, &ossl_x509extfactory_type, (ctx)); \
@@ -69,6 +72,7 @@ ossl_x509ext_new(X509_EXTENSION *ext)
X509_EXTENSION *new;
VALUE obj;
+ obj = NewX509Ext(cX509Ext);
if (!ext) {
new = X509_EXTENSION_new();
} else {
@@ -77,7 +81,7 @@ ossl_x509ext_new(X509_EXTENSION *ext)
if (!new) {
ossl_raise(eX509ExtError, NULL);
}
- WrapX509Ext(cX509Ext, obj, new);
+ SetX509Ext(obj, new);
return obj;
}
@@ -258,6 +262,7 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
valstr = rb_str_new2(RTEST(critical) ? "critical," : "");
rb_str_append(valstr, value);
GetX509ExtFactory(self, ctx);
+ obj = NewX509Ext(cX509Ext);
#ifdef HAVE_X509V3_EXT_NCONF_NID
rconf = rb_iv_get(self, "@config");
conf = NIL_P(rconf) ? NULL : GetConfigPtr(rconf);
@@ -270,7 +275,7 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
ossl_raise(eX509ExtError, "%s = %s",
RSTRING_PTR(oid), RSTRING_PTR(value));
}
- WrapX509Ext(cX509Ext, obj, ext);
+ SetX509Ext(obj, ext);
return obj;
}
@@ -284,10 +289,11 @@ ossl_x509ext_alloc(VALUE klass)
X509_EXTENSION *ext;
VALUE obj;
+ obj = NewX509Ext(klass);
if(!(ext = X509_EXTENSION_new())){
ossl_raise(eX509ExtError, NULL);
}
- WrapX509Ext(klass, obj, ext);
+ SetX509Ext(obj, ext);
return obj;
}