summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--ext/openssl/ossl_engine.c6
-rw-r--r--test/openssl/test_engine.rb15
3 files changed, 27 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 972e26dcc85..610e490204b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Jul 22 09:09:43 2011 Martin Bosslet <Martin.Bosslet@googlemail.com>
+
+ * 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]
+
Fri Jul 22 06:37:13 2011 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* lib/csv.rb: Do not modify CSV.generate's argument [ruby-core:38356]
diff --git a/ext/openssl/ossl_engine.c b/ext/openssl/ossl_engine.c
index 111e418f91e..79f51b8cdb6 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);
}
diff --git a/test/openssl/test_engine.rb b/test/openssl/test_engine.rb
new file mode 100644
index 00000000000..6d90e34398a
--- /dev/null
+++ b/test/openssl/test_engine.rb
@@ -0,0 +1,15 @@
+require_relative 'utils'
+
+if defined?(OpenSSL)
+
+class OpenSSL::TestEngine < Test::Unit::TestCase
+
+ def test_engines_free # [ruby-dev:44173]
+ OpenSSL::Engine.load
+ OpenSSL::Engine.engines
+ OpenSSL::Engine.engines
+ end
+
+end
+
+end