Added cleanup for the module handlers and validators

This commit is contained in:
Stig Telfer 2016-02-01 11:30:20 +00:00
parent 55d2451b90
commit 7963a2deaa
5 changed files with 91 additions and 3 deletions

View File

@ -535,7 +535,9 @@ int kore_msg_register(u_int8_t,
void (*cb)(struct kore_msg *, const void *));
void kore_domain_init(void);
void kore_domain_cleanup(void);
int kore_domain_new(char *);
void kore_domain_free(struct kore_domain *);
void kore_module_init(void);
void kore_module_reload(int);
void kore_module_onload(void);
@ -547,6 +549,7 @@ void kore_module_load(const char *, const char *);
void kore_domain_sslstart(struct kore_domain *);
int kore_module_handler_new(const char *, const char *,
const char *, const char *, int);
void kore_module_handler_free(struct kore_module_handle *);
struct kore_domain *kore_domain_lookup(const char *);
struct kore_module_handle *kore_module_handler_find(const char *,

View File

@ -42,6 +42,17 @@ kore_domain_init(void)
TAILQ_INIT(&domains);
}
void
kore_domain_cleanup(void)
{
struct kore_domain *dom;
while ((dom=TAILQ_FIRST(&domains)) != NULL) {
TAILQ_REMOVE(&domains, dom, list);
kore_domain_free(dom);
}
}
int
kore_domain_new(char *domain)
{
@ -71,6 +82,49 @@ kore_domain_new(char *domain)
return (KORE_RESULT_OK);
}
void
kore_domain_free(struct kore_domain *dom)
{
struct kore_module_handle *hdlr;
if (dom != NULL) {
if (primary_dom == dom) {
primary_dom = NULL;
}
TAILQ_REMOVE(&domains, dom, list);
if (dom->domain != NULL) {
kore_mem_free(dom->domain);
}
#if !defined(KORE_NO_TLS)
if (dom->ssl_ctx != NULL) {
SSL_CTX_free(dom->ssl_ctx);
}
if (dom->cafile != NULL) {
kore_mem_free(dom->cafile);
}
if (dom->certkey != NULL) {
kore_mem_free(dom->certkey);
}
if (dom->certfile != NULL) {
kore_mem_free(dom->certfile);
}
if (dom->crlfile != NULL) {
kore_mem_free(dom->crlfile);
}
#endif
/* Drop all handlers associated with this domain */
while ((hdlr=TAILQ_FIRST(&(dom->handlers))) != NULL) {
TAILQ_REMOVE(&(dom->handlers), hdlr, list);
kore_module_handler_free(hdlr);
}
kore_mem_free(dom);
}
}
void
kore_domain_sslstart(struct kore_domain *dom)
{
@ -179,7 +233,9 @@ kore_domain_sslstart(struct kore_domain *dom)
SSL_CTX_set_tlsext_servername_callback(dom->ssl_ctx, kore_tls_sni_cb);
kore_mem_free(dom->certfile);
dom->certfile = NULL;
kore_mem_free(dom->certkey);
dom->certkey = NULL;
#endif
}

View File

@ -421,6 +421,7 @@ kore_server_start(void)
kore_platform_event_cleanup();
kore_connection_cleanup();
kore_domain_cleanup();
net_cleanup();
}

View File

@ -185,9 +185,7 @@ kore_module_handler_new(const char *path, const char *domain,
if (hdlr->type == HANDLER_TYPE_DYNAMIC) {
if (regcomp(&(hdlr->rctx), hdlr->path,
REG_EXTENDED | REG_NOSUB)) {
kore_mem_free(hdlr->func);
kore_mem_free(hdlr->path);
kore_mem_free(hdlr);
kore_module_handler_free(hdlr);
kore_debug("regcomp() on %s failed", path);
return (KORE_RESULT_ERROR);
}
@ -197,6 +195,35 @@ kore_module_handler_new(const char *path, const char *domain,
return (KORE_RESULT_OK);
}
void
kore_module_handler_free(struct kore_module_handle *hdlr)
{
struct kore_handler_params *param;
if (hdlr != NULL) {
if (hdlr->func != NULL) {
kore_mem_free(hdlr->func);
}
if (hdlr->path != NULL) {
kore_mem_free(hdlr->path);
}
if (hdlr->dom != NULL) {
TAILQ_REMOVE(&(hdlr->dom->handlers), hdlr, list);
}
regfree(&(hdlr->rctx));
/* Drop all validators associated with this handler */
while ((param=TAILQ_FIRST(&(hdlr->params))) != NULL) {
TAILQ_REMOVE(&(hdlr->params), param, list);
if (param->name != NULL) {
kore_mem_free(param->name);
}
kore_mem_free(param);
}
kore_mem_free(hdlr);
}
}
struct kore_module_handle *
kore_module_handler_find(const char *domain, const char *path)
{

View File

@ -370,6 +370,7 @@ kore_worker_entry(struct kore_worker *kw)
kore_platform_event_cleanup();
kore_connection_cleanup();
kore_domain_cleanup();
#if !defined(KORE_NO_HTTP)
http_cleanup();
#endif