a6d5b6
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
a6d5b6
index 7be4fb4..ab3865a 100644
a6d5b6
--- a/src/event/ngx_event_openssl.c
a6d5b6
+++ b/src/event/ngx_event_openssl.c
a6d5b6
@@ -727,16 +727,24 @@ ngx_ssl_load_certificate_key(ngx_pool_t *pool, char **err,
a6d5b6
             return NULL;
a6d5b6
         }
a6d5b6
 
a6d5b6
+        if (!ENGINE_init(engine)) {
a6d5b6
+            *err = "ENGINE_init() failed";
a6d5b6
+            ENGINE_free(engine);
a6d5b6
+            return NULL;
a6d5b6
+        }
a6d5b6
+
a6d5b6
         *last++ = ':';
a6d5b6
 
a6d5b6
         pkey = ENGINE_load_private_key(engine, (char *) last, 0, 0);
a6d5b6
 
a6d5b6
         if (pkey == NULL) {
a6d5b6
             *err = "ENGINE_load_private_key() failed";
a6d5b6
+            ENGINE_finish(engine);
a6d5b6
             ENGINE_free(engine);
a6d5b6
             return NULL;
a6d5b6
         }
a6d5b6
 
a6d5b6
+        ENGINE_finish(engine);
a6d5b6
         ENGINE_free(engine);
a6d5b6
 
a6d5b6
         return pkey;