forked from cory/tildefriends
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:
@ -334,6 +334,13 @@ static JSValue _httpd_websocket_upgrade(JSContext* context, JSValueConst this_va
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
static void _httpd_cleanup_callback(void* user_data)
|
||||
{
|
||||
http_handler_data_t* data = user_data;
|
||||
JS_FreeValue(data->context, data->callback);
|
||||
tf_free(data);
|
||||
}
|
||||
|
||||
static JSValue _httpd_endpoint_all(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_http_t* http = JS_GetOpaque(this_val, _httpd_class_id);
|
||||
@ -341,7 +348,7 @@ static JSValue _httpd_endpoint_all(JSContext* context, JSValueConst this_val, in
|
||||
http_handler_data_t* data = tf_malloc(sizeof(http_handler_data_t));
|
||||
*data = (http_handler_data_t) { .context = context, .callback = JS_DupValue(context, argv[1]) };
|
||||
/* TODO: This leaks the callback. */
|
||||
tf_http_add_handler(http, pattern, _httpd_callback, data);
|
||||
tf_http_add_handler(http, pattern, _httpd_callback, _httpd_cleanup_callback, data);
|
||||
JS_FreeCString(context, pattern);
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
@ -527,11 +534,11 @@ void tf_httpd_register(JSContext* context)
|
||||
tf_http_set_trace(http, tf_task_get_trace(task));
|
||||
JS_SetOpaque(httpd, http);
|
||||
|
||||
tf_http_add_handler(http, "/debug", _httpd_endpoint_debug, task);
|
||||
tf_http_add_handler(http, "/disconnections", _httpd_endpoint_disconnections, task);
|
||||
tf_http_add_handler(http, "/hitches", _httpd_endpoint_hitches, task);
|
||||
tf_http_add_handler(http, "/mem", _httpd_endpoint_mem, task);
|
||||
tf_http_add_handler(http, "/trace", _httpd_endpoint_trace, task);
|
||||
tf_http_add_handler(http, "/debug", _httpd_endpoint_debug, NULL, task);
|
||||
tf_http_add_handler(http, "/disconnections", _httpd_endpoint_disconnections, NULL, task);
|
||||
tf_http_add_handler(http, "/hitches", _httpd_endpoint_hitches, NULL, task);
|
||||
tf_http_add_handler(http, "/mem", _httpd_endpoint_mem, NULL, task);
|
||||
tf_http_add_handler(http, "/trace", _httpd_endpoint_trace, NULL, task);
|
||||
|
||||
JS_SetPropertyStr(context, httpd, "handlers", JS_NewObject(context));
|
||||
JS_SetPropertyStr(context, httpd, "all", JS_NewCFunction(context, _httpd_endpoint_all, "all", 2));
|
||||
|
Reference in New Issue
Block a user