Fixed a few more good leaks. Now there are just some unclean shutdown issues.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4803 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -244,60 +244,6 @@ bool tf_util_report_error(JSContext* context, JSValue value)
|
||||
return is_error;
|
||||
}
|
||||
|
||||
typedef struct _timeout_t {
|
||||
uv_timer_t _timer;
|
||||
tf_task_t* _task;
|
||||
JSValue _callback;
|
||||
} timeout_t;
|
||||
|
||||
static void _handle_closed(uv_handle_t* handle)
|
||||
{
|
||||
timeout_t* timeout = handle->data;
|
||||
tf_free(timeout);
|
||||
}
|
||||
|
||||
static void _util_timeoutCallback(uv_timer_t* handle)
|
||||
{
|
||||
timeout_t* timeout = handle->data;
|
||||
tf_trace_begin(tf_task_get_trace(timeout->_task), "_util_timeoutCallback");
|
||||
JSContext* context = tf_task_get_context(timeout->_task);
|
||||
JSValue result = JS_Call(
|
||||
context,
|
||||
timeout->_callback,
|
||||
JS_NULL,
|
||||
0,
|
||||
NULL);
|
||||
tf_util_report_error(context, result);
|
||||
JS_FreeValue(context, result);
|
||||
JS_FreeValue(context, timeout->_callback);
|
||||
tf_trace_end(tf_task_get_trace(timeout->_task));
|
||||
uv_close((uv_handle_t*)handle, _handle_closed);
|
||||
}
|
||||
|
||||
static JSValue _util_setTimeout(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_task_t* task = JS_GetContextOpaque(context);
|
||||
|
||||
timeout_t* timeout = tf_malloc(sizeof(timeout_t));
|
||||
*timeout = (timeout_t)
|
||||
{
|
||||
._task = task,
|
||||
._callback = JS_DupValue(context, argv[0]),
|
||||
._timer = { .data = timeout },
|
||||
};
|
||||
|
||||
uv_timer_init(tf_task_get_loop(task), &timeout->_timer);
|
||||
|
||||
int64_t duration;
|
||||
JS_ToInt64(context, &duration, argv[1]);
|
||||
if (uv_timer_start(&timeout->_timer, _util_timeoutCallback, duration, 0) != 0)
|
||||
{
|
||||
JS_FreeValue(context, timeout->_callback);
|
||||
tf_free(timeout);
|
||||
}
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
static JSValue _util_parseHttpRequest(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
JSValue result = JS_UNDEFINED;
|
||||
@ -491,7 +437,6 @@ void tf_util_register(JSContext* context)
|
||||
JS_SetPropertyStr(context, global, "bip39Words", JS_NewCFunction(context, _util_bip39_words, "bip39Words", 1));
|
||||
JS_SetPropertyStr(context, global, "bip39Bytes", JS_NewCFunction(context, _util_bip39_bytes, "bip39Bytes", 1));
|
||||
JS_SetPropertyStr(context, global, "print", JS_NewCFunction(context, _util_print, "print", 1));
|
||||
JS_SetPropertyStr(context, global, "setTimeout", JS_NewCFunction(context, _util_setTimeout, "setTimeout", 2));
|
||||
JS_SetPropertyStr(context, global, "parseHttpRequest", JS_NewCFunction(context, _util_parseHttpRequest, "parseHttpRequest", 2));
|
||||
JS_SetPropertyStr(context, global, "parseHttpResponse", JS_NewCFunction(context, _util_parseHttpResponse, "parseHttpResponse", 2));
|
||||
JS_SetPropertyStr(context, global, "sha1Digest", JS_NewCFunction(context, _util_sha1_digest, "sha1Digest", 1));
|
||||
|
Reference in New Issue
Block a user