Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions Src/envar.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ PTCHAR StrAlloc(SIZE_T strlen)
return (PTCHAR)GlobalAlloc(GPTR, strlen*sizeof(TCHAR));
}

/* Frees a string. */
void StrFree(PTCHAR hVar)
/* Frees a string and clears the caller's pointer, so a second free is a no-op. */
void StrFree(PTCHAR* phVar)
{
GlobalFree(hVar);
hVar = NULL;
GlobalFree(*phVar);
*phVar = NULL;
}

/* Returns the string size. */
Expand All @@ -76,7 +76,7 @@ BOOL StrReAlloc(PTCHAR* phVar, int strlen)
if (!temp) return 0;
for (i = 0; i < StrSize(*phVar); i++)
temp[i] = (*phVar)[i];
StrFree(*phVar);
StrFree(phVar);
*phVar = temp;

return 1;
Expand All @@ -93,9 +93,9 @@ void AllocStrs(void)
/* Frees allocated buffers. */
void CleanUp(void)
{
if (gptVarName) StrFree(gptVarName);
if (gptPathString) StrFree(gptPathString);
if (gptBuffer) StrFree(gptBuffer);
if (gptVarName) StrFree(&gptVarName);
if (gptPathString) StrFree(&gptPathString);
if (gptBuffer) StrFree(&gptBuffer);

SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, (WPARAM)NULL, (LPARAM)HKCU_STR, 0, 100, 0);
}
Expand Down Expand Up @@ -557,13 +557,12 @@ __declspec(dllexport) void Update(HWND hwndParent, int string_size, TCHAR *varia
pushstring(UpdateVar());
}

/* Our DLL entry point, this is called when we first load up our DLL. */
/* Our DLL entry point, this is called when we first load up our DLL.
No CleanUp() on DLL_PROCESS_DETACH: NSISPluginCallback() already ran it at NSPIM_UNLOAD, a second run
freed the buffers twice and corrupted the installer's heap. */
BOOL WINAPI _DllMainCRTStartup(HINSTANCE hInst, DWORD ul_reason_for_call, LPVOID lpReserved)
{
hInstance = hInst;

if (ul_reason_for_call == DLL_PROCESS_DETACH)
CleanUp();

return TRUE;
}