From 84e835fe4a68586fcb17adc2a6140c737c83dd62 Mon Sep 17 00:00:00 2001 From: emboss Date: Fri, 22 Jul 2011 00:13:07 +0000 Subject: * ext/openssl/ossl_engine.c: Avoid double free of ENGINE reference. * test/openssl/test_engine.rb: Add a test for it. Thanks to Ippei Obayashi for providing the patch. [ Ruby 1.9 - Bug #5062 ] [ruby-dev:44173] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32604 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/openssl/ossl_engine.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ext/openssl') diff --git a/ext/openssl/ossl_engine.c b/ext/openssl/ossl_engine.c index 111e418f91..79f51b8cdb 100644 --- a/ext/openssl/ossl_engine.c +++ b/ext/openssl/ossl_engine.c @@ -115,7 +115,11 @@ ossl_engine_s_engines(VALUE klass) ary = rb_ary_new(); for(e = ENGINE_get_first(); e; e = ENGINE_get_next(e)){ - WrapEngine(klass, obj, e); + /* 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); rb_ary_push(ary, obj); } -- cgit v1.2.3