aboutsummaryrefslogtreecommitdiffstats
path: root/api/namespace.c
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2020-10-15 12:38:05 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2020-10-30 16:51:00 +0100
commit1f87c307f6c7bcda951a2d0d9fadc50fbc558391 (patch)
treeb19f0713d9f565e5a30a6934c9868fe2991e95a4 /api/namespace.c
parentapi: remove dead code (diff)
downloadwintun-1f87c307f6c7bcda951a2d0d9fadc50fbc558391.tar.xz
wintun-1f87c307f6c7bcda951a2d0d9fadc50fbc558391.zip
api: log out-of-memory errors too
It's not likely the write to log will succeed in low memory condition thou. Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'api/namespace.c')
-rw-r--r--api/namespace.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/api/namespace.c b/api/namespace.c
index 944b24b..3d7d563 100644
--- a/api/namespace.c
+++ b/api/namespace.c
@@ -13,26 +13,22 @@ static BCRYPT_ALG_HANDLE AlgProvider;
static WCHAR *
NormalizeStringAlloc(_In_ NORM_FORM NormForm, _In_z_ const WCHAR *Source)
{
- WCHAR *Result = NULL;
HANDLE Heap = GetProcessHeap();
int Len = NormalizeString(NormForm, Source, -1, NULL, 0);
- for (int i = 0; i < 10; ++i)
+ for (;;)
{
- if (Result)
- HeapFree(Heap, 0, Result);
- Result = HeapAlloc(Heap, 0, sizeof(WCHAR) * Len);
- if (!Result)
- return NULL;
- Len = NormalizeString(NormForm, Source, -1, Result, Len);
+ WCHAR *Str = HeapAlloc(Heap, 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 Result;
- if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
- break;
+ return Str;
+ DWORD Result = GetLastError();
+ HeapFree(Heap, 0, Str);
+ if (Result != ERROR_INSUFFICIENT_BUFFER)
+ return LOG_ERROR(L"Failed", Result), NULL;
Len = -Len;
}
- if (Result)
- HeapFree(Heap, 0, Result);
- return NULL;
}
static void