1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2026-01-07 11:03:55 +00:00

Fixed MessagePump shutdown to wait in an alertable state, fixing a scenario where memory was leaked because an APC was never called, because the event thread was not alertable while it was waiting for the apc thread to shutdown. Also fixed an edge case crash that could occur when a dispatcher was shut down.

This commit is contained in:
Bryan Roe
2022-08-09 20:33:20 -07:00
parent 373b0b424d
commit 80b14d0163
2 changed files with 9 additions and 3 deletions

View File

@@ -2324,6 +2324,7 @@ duk_ret_t ILibDuktape_GenericMarshal_GlobalCallback_StartDispatcher(duk_context
}
void __stdcall ILibDuktape_GenericMarshal_GlobalCallback_EndDispatcher_APC(ULONG_PTR u)
{
if (!ILibMemory_CanaryOK((void*)u)) { return; }
((Duktape_GlobalGeneric_Data*)u)->dispatch->finished = 1;
CloseHandle(((Duktape_GlobalGeneric_Data*)u)->dispatch->WorkerThreadHandle);
}
@@ -2339,7 +2340,7 @@ duk_ret_t ILibDuktape_GenericMarshal_GlobalCallback_EndDispatcher(duk_context *c
data = (Duktape_GlobalGeneric_Data*)duk_get_pointer(ctx, -1);
if (data == NULL) { return(ILibDuktape_Error(ctx, "Internal Error")); }
if (data->dispatch == NULL || data->dispatch->WorkerThreadHandle == NULL) { return(ILibDuktape_Error(ctx, "No Dispatcher")); }
if (data->dispatch == NULL || !ILibMemory_CanaryOK(data->dispatch) || data->dispatch->WorkerThreadHandle == NULL) { return(ILibDuktape_Error(ctx, "No Dispatcher")); }
data->dispatch->retValue = Duktape_GetPointerProperty(ctx, 0, "_ptr");
QueueUserAPC((PAPCFUNC)ILibDuktape_GenericMarshal_GlobalCallback_EndDispatcher_APC, data->dispatch->WorkerThreadHandle, (ULONG_PTR)data);