diff --git a/inc/context.h b/inc/context.h index cccd9f6..b20dd38 100644 --- a/inc/context.h +++ b/inc/context.h @@ -20,6 +20,7 @@ typedef struct { int loglevel; const char *http_options[40]; TS_RESP_CTX *ts_ctx; + CONF *conf; } rfc3161_context; struct rfc3161_option { diff --git a/inc/utils.h b/inc/utils.h index e225f38..d6ab201 100644 --- a/inc/utils.h +++ b/inc/utils.h @@ -8,5 +8,6 @@ void log_hex(rfc3161_context *ct, int priority, char *id, unsigned char *content, int content_length); int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd); static char *rand_string(char *str, size_t size); +void free_uts_context(rfc3161_context *context); int g_uts_sig_up; int g_uts_sig; diff --git a/src/lib/http.c b/src/lib/http.c index a19ea77..748a512 100644 --- a/src/lib/http.c +++ b/src/lib/http.c @@ -205,7 +205,7 @@ int http_server_start(char *conffile, char *conf_wd, bool stdout_dbg) { // Stop the server. mg_stop(ctx); - free(ct); + free_uts_context(ct); free_ssl(); return 0; diff --git a/src/lib/rfc3161.c b/src/lib/rfc3161.c index 20f0bf8..f0307eb 100644 --- a/src/lib/rfc3161.c +++ b/src/lib/rfc3161.c @@ -66,7 +66,7 @@ int add_oid_section(rfc3161_context *ct, CONF *conf) { return 1; } -void init_ssl(){ +void init_ssl() { SSL_load_error_strings(); ERR_load_BIO_strings(); SSL_library_init(); @@ -74,6 +74,12 @@ void init_ssl(){ } void free_ssl() { + CONF_modules_unload(1); + EVP_cleanup(); + // ENGINE_cleanup(); + ERR_remove_state(1); + CRYPTO_cleanup_all_ex_data(); + EVP_cleanup(); ERR_free_strings(); } diff --git a/src/lib/utils.c b/src/lib/utils.c index 6f3fbf3..430373a 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -265,8 +265,9 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) { int ret = 1; int http_counter = 0; - CONF *conf = load_config_file(ct, conf_file); - if (conf == NULL) + NCONF_free(ct->conf); + ct->conf = load_config_file(ct, conf_file); + if (ct->conf == NULL) goto end; // first pass to set the loglevel as soon as possible @@ -274,7 +275,7 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) { int type = rfc3161_options[i].type; const char *name = rfc3161_options[i].name; const char *default_value = rfc3161_options[i].default_value; - const char *value = NCONF_get_string(conf, MAIN_CONF_SECTION, name); + const char *value = NCONF_get_string(ct->conf, MAIN_CONF_SECTION, name); if (value == NULL) { uts_logger(ct, LOG_NOTICE, "configuration param['%s'] not set, using default: '%s'", @@ -299,7 +300,7 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) { int type = rfc3161_options[i].type; const char *name = rfc3161_options[i].name; const char *default_value = rfc3161_options[i].default_value; - const char *value = NCONF_get_string(conf, MAIN_CONF_SECTION, name); + const char *value = NCONF_get_string(ct->conf, MAIN_CONF_SECTION, name); if (value == NULL) { uts_logger(ct, LOG_NOTICE, "configuration param['%s'] not set, using default: '%s'", @@ -325,9 +326,9 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) { ct->http_options[http_counter] = NULL; } - if (!add_oid_section(ct, conf)) + if (!add_oid_section(ct, ct->conf)) ret = 0; - ct->ts_ctx = create_tsctx(ct, conf, NULL, NULL); + ct->ts_ctx = create_tsctx(ct, ct->conf, NULL, NULL); if (ct->ts_ctx == NULL) ret = 0; chdir("/"); @@ -337,3 +338,9 @@ end: chdir("/"); return 0; } + +void free_uts_context(rfc3161_context *context) { + TS_RESP_CTX_free(context->ts_ctx); + NCONF_free(context->conf); + free(context); +}