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