mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-18 09:13:14 +00:00
Fixed memory leak that occurs if agent is shutdown while spawned processes are still open.
This commit is contained in:
@@ -169,7 +169,21 @@ duk_ret_t ILibDuktape_ChildProcess_Kill(duk_context *ctx)
|
|||||||
duk_push_this(ctx);
|
duk_push_this(ctx);
|
||||||
ILibDuktape_ChildProcess_SubProcess *p = (ILibDuktape_ChildProcess_SubProcess*)Duktape_GetBufferProperty(ctx, -1, ILibDuktape_ChildProcess_MemBuf);
|
ILibDuktape_ChildProcess_SubProcess *p = (ILibDuktape_ChildProcess_SubProcess*)Duktape_GetBufferProperty(ctx, -1, ILibDuktape_ChildProcess_MemBuf);
|
||||||
|
|
||||||
if (p != NULL) { ILibProcessPipe_Process_SoftKill(p->childProcess); }
|
if (p != NULL)
|
||||||
|
{
|
||||||
|
//printf("CTX shutting down: %d [%p]\n", duk_ctx_shutting_down(ctx), p->childProcess);
|
||||||
|
if (p->childProcess != NULL)
|
||||||
|
{
|
||||||
|
if (duk_ctx_shutting_down(ctx) == 0)
|
||||||
|
{
|
||||||
|
ILibProcessPipe_Process_SoftKill(p->childProcess);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ILibProcessPipe_Process_HardKill(p->childProcess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
duk_ret_t ILibDuktape_ChildProcess_waitExit(duk_context *ctx)
|
duk_ret_t ILibDuktape_ChildProcess_waitExit(duk_context *ctx)
|
||||||
|
|||||||
@@ -495,6 +495,16 @@ void ILibProcessPipe_Process_SoftKill(ILibProcessPipe_Process p)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ILibProcessPipe_Process_HardKill(ILibProcessPipe_Process p)
|
||||||
|
{
|
||||||
|
if (!ILibMemory_CanaryOK(p)) { return; }
|
||||||
|
|
||||||
|
ILibProcessPipe_Process_SoftKill(p);
|
||||||
|
ILibProcessPipe_Process_Destroy(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_Manager pipeManager, char* target, char* const* parameters, ILibProcessPipe_SpawnTypes spawnType, void *sid, void *envvars, int extraMemorySize)
|
ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_Manager pipeManager, char* target, char* const* parameters, ILibProcessPipe_SpawnTypes spawnType, void *sid, void *envvars, int extraMemorySize)
|
||||||
{
|
{
|
||||||
ILibProcessPipe_Process_Object* retVal = NULL;
|
ILibProcessPipe_Process_Object* retVal = NULL;
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
|
|||||||
#define ILibProcessPipe_Manager_SpawnProcessEx3(pipeManager, target, parameters, spawnType, sessionId, extraMemorySize) ILibProcessPipe_Manager_SpawnProcessEx4(pipeManager, target, parameters, spawnType, sessionId, NULL, extraMemorySize)
|
#define ILibProcessPipe_Manager_SpawnProcessEx3(pipeManager, target, parameters, spawnType, sessionId, extraMemorySize) ILibProcessPipe_Manager_SpawnProcessEx4(pipeManager, target, parameters, spawnType, sessionId, NULL, extraMemorySize)
|
||||||
#define ILibProcessPipe_Manager_SpawnProcessWithExtraPipeMemory(pipeManager, target, parameters, memorySize) ILibProcessPipe_Manager_SpawnProcessEx2(pipeManager, target, parameters, ILibProcessPipe_SpawnTypes_DEFAULT, memorySize)
|
#define ILibProcessPipe_Manager_SpawnProcessWithExtraPipeMemory(pipeManager, target, parameters, memorySize) ILibProcessPipe_Manager_SpawnProcessEx2(pipeManager, target, parameters, ILibProcessPipe_SpawnTypes_DEFAULT, memorySize)
|
||||||
void ILibProcessPipe_Process_SoftKill(ILibProcessPipe_Process p);
|
void ILibProcessPipe_Process_SoftKill(ILibProcessPipe_Process p);
|
||||||
|
void ILibProcessPipe_Process_HardKill(ILibProcessPipe_Process p);
|
||||||
void ILibProcessPipe_Process_AddHandlers(ILibProcessPipe_Process module, int bufferSize, ILibProcessPipe_Process_ExitHandler exitHandler, ILibProcessPipe_Process_OutputHandler stdOut, ILibProcessPipe_Process_OutputHandler stdErr, ILibProcessPipe_Process_SendOKHandler sendOk, void *user);
|
void ILibProcessPipe_Process_AddHandlers(ILibProcessPipe_Process module, int bufferSize, ILibProcessPipe_Process_ExitHandler exitHandler, ILibProcessPipe_Process_OutputHandler stdOut, ILibProcessPipe_Process_OutputHandler stdErr, ILibProcessPipe_Process_SendOKHandler sendOk, void *user);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
void ILibProcessPipe_Process_RemoveHandlers(ILibProcessPipe_Process module);
|
void ILibProcessPipe_Process_RemoveHandlers(ILibProcessPipe_Process module);
|
||||||
|
|||||||
Reference in New Issue
Block a user