properly initialize script_cmd_args for each SetScript

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5046 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2007-04-10 20:41:01 +00:00
parent fb3bcd24be
commit 3a657559b0

View file

@ -76,13 +76,23 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmd
return msg.wParam; return msg.wParam;
} }
void SetScript(const char *script) void SetScript(const char *script, bool clearArgs = true)
{ {
if (g_sdata.script) if (g_sdata.script)
{ {
GlobalFree(g_sdata.script); GlobalFree(g_sdata.script);
} }
if (clearArgs)
{
if (g_sdata.script_cmd_args);
{
GlobalFree(g_sdata.script_cmd_args);
}
g_sdata.script_cmd_args = (char *) GlobalAlloc(GPTR, 1)
}
g_sdata.script = (char *) GlobalAlloc(GPTR, lstrlen(script) + 1); g_sdata.script = (char *) GlobalAlloc(GPTR, lstrlen(script) + 1);
lstrcpy(g_sdata.script, script); lstrcpy(g_sdata.script, script);
} }
@ -144,7 +154,7 @@ void ProcessCommandLine()
} }
else else
{ {
SetScript(argv[i]); SetScript(argv[i], false);
} }
} }
@ -182,7 +192,6 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
RestoreCompressor(); RestoreCompressor();
SetScript(""); SetScript("");
g_sdata.compressor = COMPRESSOR_NONE_SELECTED; g_sdata.compressor = COMPRESSOR_NONE_SELECTED;
g_sdata.script_cmd_args = (char *) GlobalAlloc(GPTR, 1);
g_sdata.userSelectCompressor = FALSE; g_sdata.userSelectCompressor = FALSE;
ProcessCommandLine(); ProcessCommandLine();