diff options
author | Simon Rozman <simon@rozman.si> | 2020-10-30 13:08:57 +0100 |
---|---|---|
committer | Simon Rozman <simon@rozman.si> | 2020-10-31 19:11:49 +0100 |
commit | 1b3af95be35ebc68f7eba842d0391fbc9d374079 (patch) | |
tree | 177daa0644dc112923085194c62edb0504d1350f /api/registry.c | |
parent | api: remove security attributes debug trap door (diff) | |
download | wintun-1b3af95be35ebc68f7eba842d0391fbc9d374079.tar.xz wintun-1b3af95be35ebc68f7eba842d0391fbc9d374079.zip |
api: selectively use temporary variable to prepare output
Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'api/registry.c')
-rw-r--r-- | api/registry.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/api/registry.c b/api/registry.c index 45e4b21..c0ebe93 100644 --- a/api/registry.c +++ b/api/registry.c @@ -181,13 +181,16 @@ RegistryQuery( { for (;;) { - *Buf = HeapAlloc(ModuleHeap, 0, *BufLen); - if (!*Buf) + BYTE *p = HeapAlloc(ModuleHeap, 0, *BufLen); + if (!p) return LOG(WINTUN_LOG_ERR, L"Out of memory"), ERROR_OUTOFMEMORY; - LSTATUS Result = RegQueryValueExW(Key, Name, NULL, ValueType, (BYTE *)*Buf, BufLen); + LSTATUS Result = RegQueryValueExW(Key, Name, NULL, ValueType, p, BufLen); if (Result == ERROR_SUCCESS) + { + *Buf = p; return ERROR_SUCCESS; - HeapFree(ModuleHeap, 0, *Buf); + } + HeapFree(ModuleHeap, 0, p); if (Result != ERROR_MORE_DATA) return Log ? LOG_ERROR(L"Querying value failed", Result) : Result; } |