1
0
mirror of https://github.com/kakwa/uts-server synced 2024-12-04 23:15:54 +01:00

fix some memory leaks on openssl context cleanup

This commit is contained in:
kakwa 2016-09-05 20:24:47 +02:00
parent aa97d4699d
commit 236f0cf04c
5 changed files with 23 additions and 8 deletions

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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();
}

View File

@ -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);
}