mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-16 00:03:45 +00:00
Added missing Canary checks, and altered engine_free to wipe memory
This commit is contained in:
@@ -93,6 +93,8 @@ void ILibDuktape_ChildProcess_SubProcess_StdIn_EndHandler(ILibDuktape_WritableSt
|
||||
void ILibDuktape_ChildProcess_SubProcess_ExitHandler(ILibProcessPipe_Process sender, int exitCode, void* user)
|
||||
{
|
||||
ILibDuktape_ChildProcess_SubProcess *p = (ILibDuktape_ChildProcess_SubProcess*)user;
|
||||
if (!ILibMemory_CanaryOK(p)) { return; }
|
||||
|
||||
p->exitCode = exitCode;
|
||||
p->childProcess = NULL;
|
||||
|
||||
@@ -112,18 +114,24 @@ void ILibDuktape_ChildProcess_SubProcess_ExitHandler(ILibProcessPipe_Process sen
|
||||
void ILibDuktape_ChildProcess_SubProcess_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int bufferLen, int* bytesConsumed, void* user)
|
||||
{
|
||||
ILibDuktape_ChildProcess_SubProcess *p = (ILibDuktape_ChildProcess_SubProcess*)user;
|
||||
if (!ILibMemory_CanaryOK(p)) { return; }
|
||||
|
||||
ILibDuktape_readableStream_WriteData(p->stdOut, buffer, bufferLen);
|
||||
*bytesConsumed = bufferLen;
|
||||
}
|
||||
void ILibDuktape_ChildProcess_SubProcess_StdErrHandler(ILibProcessPipe_Process sender, char *buffer, int bufferLen, int* bytesConsumed, void* user)
|
||||
{
|
||||
ILibDuktape_ChildProcess_SubProcess *p = (ILibDuktape_ChildProcess_SubProcess*)user;
|
||||
if (!ILibMemory_CanaryOK(p)) { return; }
|
||||
|
||||
ILibDuktape_readableStream_WriteData(p->stdErr, buffer, bufferLen);
|
||||
*bytesConsumed = bufferLen;
|
||||
}
|
||||
void ILibDuktape_ChildProcess_SubProcess_SendOK(ILibProcessPipe_Process sender, void* user)
|
||||
{
|
||||
ILibDuktape_ChildProcess_SubProcess *p = (ILibDuktape_ChildProcess_SubProcess*)user;
|
||||
if (!ILibMemory_CanaryOK(p)) { return; }
|
||||
|
||||
ILibDuktape_WritableStream_Ready(p->stdIn);
|
||||
}
|
||||
duk_ret_t ILibDuktape_ChildProcess_Kill(duk_context *ctx)
|
||||
@@ -161,11 +169,10 @@ ILibDuktape_ChildProcess_SubProcess* ILibDuktape_ChildProcess_SpawnedProcess_PUS
|
||||
ILibDuktape_WriteID(ctx, "childProcess.subProcess");
|
||||
duk_push_pointer(ctx, mProcess); // [ChildProcess][ptr]
|
||||
duk_put_prop_string(ctx, -2, ILibDuktape_ChildProcess_Process); // [ChildProcess]
|
||||
duk_push_fixed_buffer(ctx, sizeof(ILibDuktape_ChildProcess_SubProcess)); // [ChildProcess][buffer]
|
||||
ILibDuktape_ChildProcess_SubProcess *retVal = (ILibDuktape_ChildProcess_SubProcess*)Duktape_GetBuffer(ctx, -1, NULL);
|
||||
|
||||
ILibDuktape_ChildProcess_SubProcess *retVal = (ILibDuktape_ChildProcess_SubProcess*)Duktape_PushBuffer(ctx, sizeof(ILibDuktape_ChildProcess_SubProcess));
|
||||
duk_put_prop_string(ctx, -2, ILibDuktape_ChildProcess_MemBuf); // [ChildProcess]
|
||||
|
||||
memset(retVal, 0, sizeof(ILibDuktape_ChildProcess_SubProcess));
|
||||
retVal->ctx = ctx;
|
||||
retVal->subProcess = duk_get_heapptr(ctx, -1);
|
||||
retVal->childProcess = mProcess;
|
||||
|
||||
@@ -1024,7 +1024,9 @@ void ILibDuktape_ScriptContainer_Engine_free(void *udata, void *ptr)
|
||||
{
|
||||
if (ptr != NULL)
|
||||
{
|
||||
size_t sz = ILibMemory_Size(ptr);
|
||||
ILibDuktape_ScriptContainer_TotalAllocations -= ILibMemory_Size(ptr);
|
||||
memset(ptr, 0xDEADBEEF, sz);
|
||||
ILibMemory_Free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ void ILibDuktape_EventEmitter_FinalizerEx(ILibHashtable sender, void *Key1, char
|
||||
int ILibDuktape_EventEmitter_HasListeners(ILibDuktape_EventEmitter *emitter, char *eventName)
|
||||
{
|
||||
int retVal = 0;
|
||||
if(emitter!=NULL && emitter->eventTable != NULL)
|
||||
if(ILibMemory_CanaryOK(emitter) && emitter!=NULL && emitter->eventTable != NULL && emitter->ctx != NULL)
|
||||
{
|
||||
ILibLinkedList eventList = ILibHashtable_Get(emitter->eventTable, NULL, eventName, (int)strnlen_s(eventName, 255));
|
||||
if (eventList != NULL)
|
||||
@@ -191,7 +191,7 @@ duk_ret_t ILibDuktape_EventEmitter_emit(duk_context *ctx)
|
||||
self = duk_get_heapptr(ctx, -1);
|
||||
duk_pop(ctx); // ...
|
||||
|
||||
if (data->eventTable == NULL || data->ctx == NULL) { duk_push_false(ctx); return(1); } // This probably means the finalizer was already run on the eventEmitter
|
||||
if(!ILibMemory_CanaryOK(data) || data->eventTable == NULL || data->ctx == NULL) { duk_push_false(ctx); return(1); } // This probably means the finalizer was already run on the eventEmitter
|
||||
|
||||
eventList = ILibHashtable_Get(data->eventTable, NULL, name, (int)nameLen);
|
||||
if (eventList == NULL)
|
||||
|
||||
Reference in New Issue
Block a user