android: Fix some crashes, callstacks, and warnings I'm seeing in the logs.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 16m27s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 16m27s
This commit is contained in:
@ -62,6 +62,7 @@ static JSValue _taskstub_set_on_print(JSContext* context, JSValueConst this_val,
|
||||
static JSValue _taskstub_loadFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static void _taskstub_on_process_exit(uv_process_t* process, int64_t status, int terminationSignal);
|
||||
static void _taskstub_finalizer(JSRuntime* runtime, JSValue value);
|
||||
static void _taskstub_cleanup(tf_taskstub_t* stub);
|
||||
|
||||
static void _tf_taskstub_run_sandbox_thread(void* data)
|
||||
{
|
||||
@ -74,12 +75,60 @@ static void _tf_taskstub_run_sandbox_thread(void* data)
|
||||
tf_task_destroy(task);
|
||||
}
|
||||
|
||||
static void _taskstub_on_handle_close(uv_handle_t* handle)
|
||||
{
|
||||
tf_taskstub_t* stub = handle->data;
|
||||
tf_task_remove_child(stub->_owner, stub);
|
||||
handle->data = NULL;
|
||||
_taskstub_cleanup(stub);
|
||||
}
|
||||
|
||||
static void _tf_taskstub_on_exit(tf_taskstub_t* stub, int64_t status, int termination_signal)
|
||||
{
|
||||
JSContext* context = tf_task_get_context(stub->_owner);
|
||||
if (!JS_IsUndefined(stub->_on_exit))
|
||||
{
|
||||
JSValue ref = JS_DupValue(context, stub->_on_exit);
|
||||
JSValue argv[] = { JS_NewInt64(context, status), JS_NewInt32(context, termination_signal) };
|
||||
JSValue result = JS_Call(context, stub->_on_exit, JS_NULL, 2, argv);
|
||||
tf_util_report_error(context, result);
|
||||
JS_FreeValue(context, result);
|
||||
JS_FreeValue(context, argv[0]);
|
||||
JS_FreeValue(context, argv[1]);
|
||||
JS_FreeValue(context, ref);
|
||||
}
|
||||
if (stub->_stream)
|
||||
{
|
||||
tf_packetstream_destroy(stub->_stream);
|
||||
stub->_stream = NULL;
|
||||
}
|
||||
tf_task_remove_child(stub->_owner, stub);
|
||||
if (stub->_process.data)
|
||||
{
|
||||
uv_close((uv_handle_t*)&stub->_process, _taskstub_on_handle_close);
|
||||
}
|
||||
else
|
||||
{
|
||||
_taskstub_cleanup(stub);
|
||||
}
|
||||
}
|
||||
|
||||
static void _tf_taskstub_packetstream_close(void* user_data)
|
||||
{
|
||||
tf_taskstub_t* stub = user_data;
|
||||
if (!stub->_process.data)
|
||||
{
|
||||
_tf_taskstub_on_exit(stub, -1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
static JSValue _taskstub_create(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_task_t* parent = tf_task_get(context);
|
||||
tf_taskstub_t* stub = tf_malloc(sizeof(tf_taskstub_t));
|
||||
memset(stub, 0, sizeof(*stub));
|
||||
stub->_stream = tf_packetstream_create();
|
||||
tf_packetstream_set_on_close(stub->_stream, _tf_taskstub_packetstream_close, stub);
|
||||
|
||||
JSValue taskObject = JS_NewObjectClass(context, _classId);
|
||||
JS_SetOpaque(taskObject, stub);
|
||||
@ -314,35 +363,10 @@ static void _taskstub_finalizer(JSRuntime* runtime, JSValue value)
|
||||
_taskstub_cleanup(stub);
|
||||
}
|
||||
|
||||
static void _taskstub_on_handle_close(uv_handle_t* handle)
|
||||
{
|
||||
tf_taskstub_t* stub = handle->data;
|
||||
tf_task_remove_child(stub->_owner, stub);
|
||||
handle->data = NULL;
|
||||
_taskstub_cleanup(stub);
|
||||
}
|
||||
|
||||
static void _taskstub_on_process_exit(uv_process_t* process, int64_t status, int terminationSignal)
|
||||
static void _taskstub_on_process_exit(uv_process_t* process, int64_t status, int termination_signal)
|
||||
{
|
||||
tf_taskstub_t* stub = process->data;
|
||||
JSContext* context = tf_task_get_context(stub->_owner);
|
||||
if (!JS_IsUndefined(stub->_on_exit))
|
||||
{
|
||||
JSValue ref = JS_DupValue(context, stub->_on_exit);
|
||||
JSValue argv[] = { JS_NewInt64(context, status), JS_NewInt32(context, terminationSignal) };
|
||||
JSValue result = JS_Call(context, stub->_on_exit, JS_NULL, 2, argv);
|
||||
tf_util_report_error(context, result);
|
||||
JS_FreeValue(context, result);
|
||||
JS_FreeValue(context, argv[0]);
|
||||
JS_FreeValue(context, argv[1]);
|
||||
JS_FreeValue(context, ref);
|
||||
}
|
||||
if (stub->_stream)
|
||||
{
|
||||
tf_packetstream_destroy(stub->_stream);
|
||||
stub->_stream = NULL;
|
||||
}
|
||||
uv_close((uv_handle_t*)process, _taskstub_on_handle_close);
|
||||
_tf_taskstub_on_exit(stub, status, termination_signal);
|
||||
}
|
||||
|
||||
static JSValue _taskstub_getExports(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
|
Reference in New Issue
Block a user