diff -aur tomcat-native-1.2.28-src/native/src/ssl.c tomcat-native-1.2.28-src.changed/native/src/ssl.c --- tomcat-native-1.2.28-src/native/src/ssl.c 2021-04-01 06:28:54.000000000 -0700 +++ tomcat-native-1.2.28-src.changed/native/src/ssl.c 2021-05-20 13:21:18.569612200 -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. @@ -815,9 +823,9 @@ if (!ENGINE_set_default(ee, ENGINE_METHOD_ALL)) err = APR_ENOTIMPL; } - /* Free our "structural" reference. */ + /* Keep 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