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