summaryrefslogtreecommitdiff
path: root/ext/openssl/ossl_engine.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_engine.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_engine.c')
-rw-r--r--ext/openssl/ossl_engine.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/ext/openssl/ossl_engine.c b/ext/openssl/ossl_engine.c
index 20dd7b0..0e9bc96 100644
--- a/ext/openssl/ossl_engine.c
+++ b/ext/openssl/ossl_engine.c
@@ -12,11 +12,13 @@
#if defined(OSSL_ENGINE_ENABLED)
-#define WrapEngine(klass, obj, engine) do { \
+#define NewEngine(klass) \
+ TypedData_Wrap_Struct((klass), &ossl_engine_type, 0)
+#define SetEngine(obj, engine) do { \
if (!(engine)) { \
ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
} \
- (obj) = TypedData_Wrap_Struct((klass), &ossl_engine_type, (engine)); \
+ RTYPEDDATA_DATA(obj) = (engine); \
} while(0)
#define GetEngine(obj, engine) do { \
TypedData_Get_Struct((obj), ENGINE, &ossl_engine_type, (engine)); \
@@ -182,11 +184,12 @@ ossl_engine_s_engines(VALUE klass)
ary = rb_ary_new();
for(e = ENGINE_get_first(); e; e = ENGINE_get_next(e)){
+ obj = NewEngine(klass);
/* Need a ref count of two here because of ENGINE_free being
* called internally by OpenSSL when moving to the next ENGINE
* and by us when releasing the ENGINE reference */
ENGINE_up_ref(e);
- WrapEngine(klass, obj, e);
+ SetEngine(obj, e);
rb_ary_push(ary, obj);
}
@@ -213,9 +216,10 @@ ossl_engine_s_by_id(VALUE klass, VALUE id)
StringValue(id);
ossl_engine_s_load(1, &id, klass);
+ obj = NewEngine(klass);
if(!(e = ENGINE_by_id(RSTRING_PTR(id))))
ossl_raise(eEngineError, NULL);
- WrapEngine(klass, obj, e);
+ SetEngine(obj, e);
if(rb_block_given_p()) rb_yield(obj);
if(!ENGINE_init(e))
ossl_raise(eEngineError, NULL);
@@ -232,10 +236,11 @@ ossl_engine_s_alloc(VALUE klass)
ENGINE *e;
VALUE obj;
+ obj = NewEngine(klass);
if (!(e = ENGINE_new())) {
ossl_raise(eEngineError, NULL);
}
- WrapEngine(klass, obj, e);
+ SetEngine(obj, e);
return obj;
}