Skip to content

Commit 26a602f

Browse files
committed
Reaction to Jeff Trawick's observations that we are double-initializing dynalinked OpenSSL Engines and Configs. Move the library teardown code so that it is torn down in the proper order, corresponding to when the library itself was initialized. And leave a little reminder that some memory diagnostics would be good if OpenSSL is built for malloc debugging. Suggested by: Geoff Thorpe git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@100288 13f79535-47bb-0310-9956-ffa450edef68
1 parent bb5ca04 commit 26a602f

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

modules/ssl/mod_ssl.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,34 @@ static const command_rec ssl_config_cmds[] = {
230230
/*
231231
* the various processing hooks
232232
*/
233+
static apr_status_t ssl_cleanup_pre_config(void *data)
234+
{
235+
/*
236+
* Try to kill the internals of the SSL library.
237+
*/
238+
#ifdef OPENSSL_VERSION_NUMBER
239+
#if OPENSSL_VERSION_NUMBER >= 0x00907001
240+
/* Corresponds to OPENSSL_load_builtin_modules():
241+
* XXX: borrowed from apps.h, but why not CONF_modules_free()
242+
* which also invokes CONF_modules_finish()?
243+
*/
244+
CONF_modules_unload(1);
245+
#endif
246+
#endif
247+
/* Corresponds to SSL_library_init: */
248+
EVP_cleanup();
249+
#if HAVE_ENGINE_LOAD_BUILTIN_ENGINES
250+
ENGINE_cleanup();
251+
#endif
252+
CRYPTO_cleanup_all_ex_data();
253+
ERR_remove_state(0);
254+
ERR_free_strings();
255+
/*
256+
* TODO: determine somewhere we can safely shove out diagnostics
257+
* (when enabled) at this late stage in the game:
258+
* CRYPTO_mem_leaks_fp(stderr);
259+
*/
260+
}
233261

234262
static int ssl_hook_pre_config(apr_pool_t *pconf,
235263
apr_pool_t *plog,
@@ -251,6 +279,12 @@ static int ssl_hook_pre_config(apr_pool_t *pconf,
251279
#endif
252280
SSL_load_error_strings();
253281

282+
/*
283+
* Let us cleanup the ssl library when the module is unloaded
284+
*/
285+
apr_pool_cleanup_register(pconf, NULL, ssl_cleanup_pre_config,
286+
apr_pool_cleanup_null);
287+
254288
/* Register us to handle mod_log_config %c/%x variables */
255289
ssl_var_log_config_register(pconf);
256290
#if 0 /* XXX */

modules/ssl/ssl_engine_init.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,13 +1251,6 @@ apr_status_t ssl_init_ModuleKill(void *data)
12511251
ssl_init_ctx_cleanup_server(sc->server);
12521252
}
12531253

1254-
/*
1255-
* Try to kill the internals of the SSL library.
1256-
*/
1257-
ERR_free_strings();
1258-
ERR_remove_state(0);
1259-
EVP_cleanup();
1260-
12611254
return APR_SUCCESS;
12621255
}
12631256

0 commit comments

Comments
 (0)