Don't leak the http handlers.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4801 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-01-27 17:11:24 +00:00
parent 55fb5dce1a
commit 14a4117aff
7 changed files with 34 additions and 10 deletions

View File

@ -68,6 +68,7 @@ typedef struct _tf_http_handler_t
{
const char* pattern;
tf_http_callback_t* callback;
tf_http_cleanup_t* cleanup;
void* user_data;
} tf_http_handler_t;
@ -656,13 +657,14 @@ int tf_http_listen(tf_http_t* http, int port, tf_tls_context_t* tls)
return assigned_port;
}
void tf_http_add_handler(tf_http_t* http, const char* pattern, tf_http_callback_t* callback, void* user_data)
void tf_http_add_handler(tf_http_t* http, const char* pattern, tf_http_callback_t* callback, tf_http_cleanup_t* cleanup, void* user_data)
{
http->handlers = tf_realloc(http->handlers, sizeof(tf_http_handler_t) * (http->handlers_count + 1));
http->handlers[http->handlers_count++] = (tf_http_handler_t)
{
.pattern = tf_strdup(pattern),
.callback = callback,
.cleanup = cleanup,
.user_data = user_data,
};
}
@ -691,6 +693,10 @@ void tf_http_destroy(tf_http_t* http)
tf_free((void*)http->handlers[i].pattern);
http->handlers[i].pattern = NULL;
}
if (http->handlers[i].cleanup)
{
http->handlers[i].cleanup(http->handlers[i].user_data);
}
}
tf_free(http->handlers);
http->handlers_count = 0;