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