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