--- tomcat-native-1.2.28-src/native/src/ssl.c 2021-04-01 06:28:54.000000000 -0700 +++ tomcat-native-1.2.28-src/native/src/ssl.c 2021-05-20 12:58:27.154317691 -0700 @@ -367,6 +367,14 @@ #endif free_dh_params(); +#ifndef OPENSSL_NO_ENGINE + if (tcn_ssl_engine != NULL) { + /* Release the SSL Engine structural reference */ + ENGINE_free(tcn_ssl_engine); + tcn_ssl_engine = NULL; + } +#endif + #if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) /* Openssl v1.1+ handles all termination automatically. Do * nothing in this case. @@ -817,7 +825,7 @@ } /* Free our "structural" reference. */ if (ee) - ENGINE_free(ee); + tcn_ssl_engine = ee; } if (err != APR_SUCCESS) { TCN_FREE_CSTRING(engine); @@ -825,7 +833,6 @@ tcn_ThrowAPRException(e, err); return (jint)err; } - tcn_ssl_engine = ee; } #endif