mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-16 00:03:45 +00:00
Fixed memory leak
This commit is contained in:
@@ -1880,36 +1880,50 @@ End Mesh Agent Duktape Abstraction
|
|||||||
char* MeshAgent_MakeAbsolutePathEx(char *basePath, char *localPath, int escapeBackSlash)
|
char* MeshAgent_MakeAbsolutePathEx(char *basePath, char *localPath, int escapeBackSlash)
|
||||||
{
|
{
|
||||||
MeshAgentHostContainer *agent = ILibMemory_CanaryOK(basePath) ? ((MeshAgentHostContainer**)ILibMemory_Extra(basePath))[0] : NULL;
|
MeshAgentHostContainer *agent = ILibMemory_CanaryOK(basePath) ? ((MeshAgentHostContainer**)ILibMemory_Extra(basePath))[0] : NULL;
|
||||||
duk_context *ctx = (agent != NULL && agent->meshCoreCtx != NULL) ? agent->meshCoreCtx : ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx(SCRIPT_ENGINE_NONE, 0, agent!=NULL?agent->chain:NULL, NULL, NULL, agent!=NULL?agent->exePath: basePath, NULL, NULL, agent!=NULL?agent->chain:NULL);
|
size_t basePathLen = strnlen_s(basePath, sizeof(ILibScratchPad2) - 4);
|
||||||
|
size_t localPathLen = strnlen_s(localPath, sizeof(ILibScratchPad2) - 4);
|
||||||
|
size_t len;
|
||||||
|
char *wd;
|
||||||
|
|
||||||
if (duk_peval_string(ctx, "require('util-pathHelper');") == 0) // [helper]
|
if (agent != NULL && agent->configPathUsesCWD != 0)
|
||||||
{
|
{
|
||||||
duk_push_string(ctx, basePath); // [helper][basePath]
|
#ifdef WIN32
|
||||||
duk_push_string(ctx, localPath); // [helper][basePath][localPath]
|
int i = ILibString_LastIndexOf(basePath, basePathLen, "\\", 1) + 1;
|
||||||
duk_push_boolean(ctx, agent!=NULL?(agent->configPathUsesCWD != 0):0); // [helper][basePath][localPath][bool]
|
wd = ILibWideToUTF8((LPWSTR)ILibScratchPad2, GetCurrentDirectoryW(sizeof(ILibScratchPad2) / 2, (LPWSTR)ILibScratchPad2));
|
||||||
if (duk_pcall(ctx, 3) == 0) // [result]
|
sprintf_s(ILibScratchPad2, sizeof(ILibScratchPad2), "%s\\%s", wd, basePath + i);
|
||||||
{
|
#else
|
||||||
if (escapeBackSlash != 0)
|
int i = ILibString_LastIndexOf(basePath, basePathLen, "/", 1) + 1;
|
||||||
{
|
getcwd(ILibScratchPad, sizeof(ILibScratchPad));
|
||||||
duk_string_split(ctx, -1, "\\"); // [result][array]
|
sprintf_s(ILibScratchPad2, sizeof(ILibScratchPad2), "%s/%s", ILibScratchPad, basePath + i);
|
||||||
duk_array_join(ctx, -1, "\\\\"); // [result][array][string]
|
#endif
|
||||||
duk_remove(ctx, -2); // [result][string]
|
}
|
||||||
duk_remove(ctx, -2); // [string]
|
else
|
||||||
}
|
{
|
||||||
duk_size_t len;
|
sprintf_s(ILibScratchPad2, sizeof(ILibScratchPad2), "%s", basePath);
|
||||||
char *buffer = Duktape_GetBuffer(ctx, -1, &len);
|
|
||||||
if (len < sizeof(ILibScratchPad2))
|
|
||||||
{
|
|
||||||
ILibScratchPad2[len] = 0;
|
|
||||||
memcpy_s(ILibScratchPad2, sizeof(ILibScratchPad2), buffer, len);
|
|
||||||
duk_pop(ctx); // ...
|
|
||||||
if (agent == NULL || agent->meshCoreCtx == NULL) { Duktape_SafeDestroyHeap(ctx); }
|
|
||||||
return(ILibScratchPad2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ILIBCRITICALEXITMSG(254, "PATH MANIPULATION ERROR");
|
len = strnlen_s(ILibScratchPad2, sizeof(ILibScratchPad2));
|
||||||
|
if (localPath[0] == '.')
|
||||||
|
{
|
||||||
|
#ifndef WIN32
|
||||||
|
sprintf_s(ILibScratchPad2 + len, sizeof(ILibScratchPad2) - len, "%s", localPath);
|
||||||
|
#else
|
||||||
|
int i = ILibString_LastIndexOf(ILibScratchPad2, len, ".", 1);
|
||||||
|
sprintf_s(ILibScratchPad2 + i, sizeof(ILibScratchPad2) - i, "%s", localPath);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
int i = ILibString_LastIndexOf(ILibScratchPad2, len, "\\", 1) + 1;
|
||||||
|
#else
|
||||||
|
int i = ILibString_LastIndexOf(ILibScratchPad2, len, "/", 1) + 1;
|
||||||
|
#endif
|
||||||
|
sprintf_s(ILibScratchPad2 + i, sizeof(ILibScratchPad2) - i, "%s", localPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("MeshAgent_MakeAbsolutePathEx[%s,%s] = %s\n", basePath, localPath, ILibScratchPad2);
|
||||||
|
return(ILibScratchPad2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MICROSTACK_NOTLS
|
#ifndef MICROSTACK_NOTLS
|
||||||
|
|||||||
@@ -1068,56 +1068,80 @@ INT_PTR CALLBACK DialogHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP
|
|||||||
ILibChain_PartialStart(dialogchain);
|
ILibChain_PartialStart(dialogchain);
|
||||||
duk_context *ctx = ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx(0, 0, dialogchain, NULL, NULL, selfexe, NULL, NULL, dialogchain);
|
duk_context *ctx = ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx(0, 0, dialogchain, NULL, NULL, selfexe, NULL, NULL, dialogchain);
|
||||||
if (duk_peval_string(ctx, "require('util-language').current.toLowerCase().split('_').join('-');") == 0) { lang = (char*)duk_safe_to_string(ctx, -1); }
|
if (duk_peval_string(ctx, "require('util-language').current.toLowerCase().split('_').join('-');") == 0) { lang = (char*)duk_safe_to_string(ctx, -1); }
|
||||||
if (duk_peval_string(ctx, "(function foo(){return(JSON.parse(_MSH().translation));})()") == 0)
|
if (duk_peval_string(ctx, "(function foo(){return(JSON.parse(_MSH().translation));})()") != 0)
|
||||||
{
|
{
|
||||||
if (DIALOG_LANG != NULL) { lang = DIALOG_LANG; }
|
duk_push_object(ctx); // [translation]
|
||||||
if (duk_has_prop_string(ctx, -1, lang))
|
duk_push_object(ctx); // [translation][en]
|
||||||
{
|
duk_push_string(ctx, "Install"); duk_put_prop_string(ctx, -2, "install");
|
||||||
duk_get_prop_string(ctx, -1, lang);
|
duk_push_string(ctx, "Uninstall"); duk_put_prop_string(ctx, -2, "uninstall");
|
||||||
|
duk_push_string(ctx, "Connect"); duk_put_prop_string(ctx, -2, "connect");
|
||||||
agentstatus = Dialog_GetTranslation(ctx, "statusDescription");
|
duk_push_string(ctx, "Disconnect"); duk_put_prop_string(ctx, -2, "disconnect");
|
||||||
if (agentstatus != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_AGENTSTATUS_TEXT), agentstatus); }
|
duk_push_string(ctx, "Update"); duk_put_prop_string(ctx, -2, "update");
|
||||||
|
duk_push_array(ctx);
|
||||||
agentversion = Dialog_GetTranslation(ctx, "agentVersion");
|
duk_push_string(ctx, "NOT INSTALLED"); duk_array_push(ctx, -2);
|
||||||
if (agentversion != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_AGENT_VERSION), agentversion); }
|
duk_push_string(ctx, "RUNNING"); duk_array_push(ctx, -2);
|
||||||
|
duk_push_string(ctx, "NOT RUNNING"); duk_array_push(ctx, -2);
|
||||||
serverlocation = Dialog_GetTranslation(ctx, "url");
|
duk_put_prop_string(ctx, -2, "status");
|
||||||
if (serverlocation != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_SERVER_LOCATION), serverlocation); }
|
duk_put_prop_string(ctx, -2, "en"); // [translation]
|
||||||
|
|
||||||
meshname = Dialog_GetTranslation(ctx, "meshName");
|
|
||||||
if (meshname != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_MESH_NAME), meshname); }
|
|
||||||
|
|
||||||
meshidentitifer = Dialog_GetTranslation(ctx, "meshId");
|
|
||||||
if (meshidentitifer != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_MESH_IDENTIFIER), meshidentitifer); }
|
|
||||||
|
|
||||||
serveridentifier = Dialog_GetTranslation(ctx, "serverId");
|
|
||||||
if (serveridentifier != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_SERVER_IDENTIFIER), serveridentifier); }
|
|
||||||
|
|
||||||
dialogdescription = Dialog_GetTranslation(ctx, "description");
|
|
||||||
if (dialogdescription != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_DESCRIPTION), dialogdescription); }
|
|
||||||
|
|
||||||
install_buttontext = Dialog_GetTranslation(ctx, "install");
|
|
||||||
update_buttontext = Dialog_GetTranslation(ctx, "update");
|
|
||||||
uninstall_buttontext = Dialog_GetTranslation(ctx, "uninstall");
|
|
||||||
cancel_buttontext = Dialog_GetTranslation(ctx, "cancel");
|
|
||||||
disconnect_buttontext = Dialog_GetTranslation(ctx, "disconnect");
|
|
||||||
if (disconnect_buttontext != NULL)
|
|
||||||
{
|
|
||||||
wcscpy_s(closeButtonText, sizeof(closeButtonText) / 2, disconnect_buttontext);
|
|
||||||
closeButtonTextSet = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uninstall_buttontext != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_UNINSTALLBUTTON), uninstall_buttontext); }
|
|
||||||
connect_buttontext = Dialog_GetTranslation(ctx, "connect");
|
|
||||||
if (connect_buttontext != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_CONNECTBUTTON), connect_buttontext); }
|
|
||||||
if (cancel_buttontext != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDCANCEL), cancel_buttontext); }
|
|
||||||
|
|
||||||
duk_get_prop_string(ctx, -1, "status"); // [Array]
|
|
||||||
state_notinstalled = Dialog_GetTranslationEx(ctx, Duktape_GetStringPropertyIndexValue(ctx, -1, 0, NULL));
|
|
||||||
state_running = Dialog_GetTranslationEx(ctx, Duktape_GetStringPropertyIndexValue(ctx, -1, 1, NULL));
|
|
||||||
state_notrunning = Dialog_GetTranslationEx(ctx, Duktape_GetStringPropertyIndexValue(ctx, -1, 2, NULL));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DIALOG_LANG != NULL) { lang = DIALOG_LANG; }
|
||||||
|
if (!duk_has_prop_string(ctx, -1, lang))
|
||||||
|
{
|
||||||
|
duk_push_string(ctx, lang); // [obj][string]
|
||||||
|
duk_string_split(ctx, -1, "-"); // [obj][string][array]
|
||||||
|
duk_array_shift(ctx, -1); // [obj][string][array][string]
|
||||||
|
lang = (char*)duk_safe_to_string(ctx, -1);
|
||||||
|
duk_dup(ctx, -4); // [obj][string][array][string][obj]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (duk_has_prop_string(ctx, -1, lang))
|
||||||
|
{
|
||||||
|
duk_get_prop_string(ctx, -1, lang);
|
||||||
|
|
||||||
|
agentstatus = Dialog_GetTranslation(ctx, "statusDescription");
|
||||||
|
if (agentstatus != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_AGENTSTATUS_TEXT), agentstatus); }
|
||||||
|
|
||||||
|
agentversion = Dialog_GetTranslation(ctx, "agentVersion");
|
||||||
|
if (agentversion != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_AGENT_VERSION), agentversion); }
|
||||||
|
|
||||||
|
serverlocation = Dialog_GetTranslation(ctx, "url");
|
||||||
|
if (serverlocation != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_SERVER_LOCATION), serverlocation); }
|
||||||
|
|
||||||
|
meshname = Dialog_GetTranslation(ctx, "meshName");
|
||||||
|
if (meshname != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_MESH_NAME), meshname); }
|
||||||
|
|
||||||
|
meshidentitifer = Dialog_GetTranslation(ctx, "meshId");
|
||||||
|
if (meshidentitifer != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_MESH_IDENTIFIER), meshidentitifer); }
|
||||||
|
|
||||||
|
serveridentifier = Dialog_GetTranslation(ctx, "serverId");
|
||||||
|
if (serveridentifier != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_SERVER_IDENTIFIER), serveridentifier); }
|
||||||
|
|
||||||
|
dialogdescription = Dialog_GetTranslation(ctx, "description");
|
||||||
|
if (dialogdescription != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_DESCRIPTION), dialogdescription); }
|
||||||
|
|
||||||
|
install_buttontext = Dialog_GetTranslation(ctx, "install");
|
||||||
|
update_buttontext = Dialog_GetTranslation(ctx, "update");
|
||||||
|
uninstall_buttontext = Dialog_GetTranslation(ctx, "uninstall");
|
||||||
|
cancel_buttontext = Dialog_GetTranslation(ctx, "cancel");
|
||||||
|
disconnect_buttontext = Dialog_GetTranslation(ctx, "disconnect");
|
||||||
|
if (disconnect_buttontext != NULL)
|
||||||
|
{
|
||||||
|
wcscpy_s(closeButtonText, sizeof(closeButtonText) / 2, disconnect_buttontext);
|
||||||
|
closeButtonTextSet = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uninstall_buttontext != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_UNINSTALLBUTTON), uninstall_buttontext); }
|
||||||
|
connect_buttontext = Dialog_GetTranslation(ctx, "connect");
|
||||||
|
if (connect_buttontext != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDC_CONNECTBUTTON), connect_buttontext); }
|
||||||
|
if (cancel_buttontext != NULL) { SetWindowTextW(GetDlgItem(hDlg, IDCANCEL), cancel_buttontext); }
|
||||||
|
|
||||||
|
duk_get_prop_string(ctx, -1, "status"); // [Array]
|
||||||
|
state_notinstalled = Dialog_GetTranslationEx(ctx, Duktape_GetStringPropertyIndexValue(ctx, -1, 0, NULL));
|
||||||
|
state_running = Dialog_GetTranslationEx(ctx, Duktape_GetStringPropertyIndexValue(ctx, -1, 1, NULL));
|
||||||
|
state_notrunning = Dialog_GetTranslationEx(ctx, Duktape_GetStringPropertyIndexValue(ctx, -1, 2, NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fileName = MeshAgent_MakeAbsolutePath(selfexe, ".msh");
|
fileName = MeshAgent_MakeAbsolutePath(selfexe, ".msh");
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2552,7 +2552,13 @@ extern void ILibDuktape_HttpStream_Init(duk_context *ctx);
|
|||||||
duk_context *ILibDuktape_ScriptContainer_InitializeJavaScriptEngine_minimal()
|
duk_context *ILibDuktape_ScriptContainer_InitializeJavaScriptEngine_minimal()
|
||||||
{
|
{
|
||||||
ILibDuktape_ContextData *ctxd = (ILibDuktape_ContextData*)ILibMemory_SmartAllocate(sizeof(ILibDuktape_ContextData));
|
ILibDuktape_ContextData *ctxd = (ILibDuktape_ContextData*)ILibMemory_SmartAllocate(sizeof(ILibDuktape_ContextData));
|
||||||
|
#ifndef MICROSTACK_NOTLS
|
||||||
|
util_openssl_init();
|
||||||
|
#endif
|
||||||
do { util_random(sizeof(ctxd->nonce), (char*)&(ctxd->nonce)); } while (ctxd->nonce == 0);
|
do { util_random(sizeof(ctxd->nonce), (char*)&(ctxd->nonce)); } while (ctxd->nonce == 0);
|
||||||
|
#ifndef MICROSTACK_NOTLS
|
||||||
|
util_openssl_uninit();
|
||||||
|
#endif
|
||||||
ctxd->threads = ILibLinkedList_Create();
|
ctxd->threads = ILibLinkedList_Create();
|
||||||
|
|
||||||
duk_context *ctx = duk_create_heap(ILibDuktape_ScriptContainer_Engine_malloc, ILibDuktape_ScriptContainer_Engine_realloc, ILibDuktape_ScriptContainer_Engine_free, ctxd, ILibDuktape_ScriptContainer_Engine_fatal);
|
duk_context *ctx = duk_create_heap(ILibDuktape_ScriptContainer_Engine_malloc, ILibDuktape_ScriptContainer_Engine_realloc, ILibDuktape_ScriptContainer_Engine_free, ctxd, ILibDuktape_ScriptContainer_Engine_fatal);
|
||||||
|
|||||||
@@ -3773,10 +3773,6 @@ void ILibChain_PartialStart(void *Chain)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (chain->nowatchdog == 0)
|
|
||||||
{
|
|
||||||
chain->WatchDogThread = ILibSpawnNormalThread(ILibChain_WatchDogStart, chain);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -3831,6 +3827,13 @@ ILibExportMethod void ILibStartChain(void *Chain)
|
|||||||
FD_ZERO(&errorset);
|
FD_ZERO(&errorset);
|
||||||
FD_ZERO(&writeset);
|
FD_ZERO(&writeset);
|
||||||
|
|
||||||
|
#if defined(ILibChain_WATCHDOG_TIMEOUT)
|
||||||
|
if (chain->TerminateFlag == 0 && chain->nowatchdog == 0)
|
||||||
|
{
|
||||||
|
chain->WatchDogThread = ILibSpawnNormalThread(ILibChain_WatchDogStart, chain);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
while (chain->TerminateFlag == 0)
|
while (chain->TerminateFlag == 0)
|
||||||
{
|
{
|
||||||
slct = 0;
|
slct = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user