diff options
author | Simon Rozman <simon@rozman.si> | 2020-10-24 22:12:47 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-10-30 16:51:01 +0100 |
commit | bf4eabb4ca3fb1d0c68b375a2a964165776e44cb (patch) | |
tree | 4fe9d219bf6c64a7447caa17eb4f33405f4d7647 /api/namespace.c | |
parent | api: add ring management (diff) | |
download | wintun-bf4eabb4ca3fb1d0c68b375a2a964165776e44cb.tar.xz wintun-bf4eabb4ca3fb1d0c68b375a2a964165776e44cb.zip |
api: switch to private heap
We must not use the process heap, as it is changeable. Client may change
it causing our HeapFree() to use wrong heap.
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'api/namespace.c')
-rw-r--r-- | api/namespace.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/api/namespace.c b/api/namespace.c index 5129bdd..8c4d4bc 100644 --- a/api/namespace.c +++ b/api/namespace.c @@ -12,18 +12,17 @@ static BCRYPT_ALG_HANDLE AlgProvider; static WCHAR * NormalizeStringAlloc(_In_ NORM_FORM NormForm, _In_z_ const WCHAR *Source) { - HANDLE Heap = GetProcessHeap(); int Len = NormalizeString(NormForm, Source, -1, NULL, 0); for (;;) { - WCHAR *Str = HeapAlloc(Heap, 0, sizeof(WCHAR) * Len); + WCHAR *Str = HeapAlloc(ModuleHeap, 0, sizeof(WCHAR) * Len); if (!Str) return LOG(WINTUN_LOG_ERR, L"Out of memory"), NULL; Len = NormalizeString(NormForm, Source, -1, Str, Len); if (Len > 0) return Str; DWORD Result = GetLastError(); - HeapFree(Heap, 0, Str); + HeapFree(ModuleHeap, 0, Str); if (Result != ERROR_INSUFFICIENT_BUFFER) return LOG_ERROR(L"Failed", Result), NULL; Len = -Len; @@ -152,7 +151,7 @@ NamespaceTakeMutex(_In_z_ const WCHAR *Pool) CloseHandle(Mutex); Mutex = NULL; cleanupPoolNorm: - HeapFree(GetProcessHeap(), 0, PoolNorm); + HeapFree(ModuleHeap, 0, PoolNorm); cleanupSha256: BCryptDestroyHash(Sha256); return Mutex; |