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/session.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 '')
-rw-r--r-- | api/session.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/api/session.c b/api/session.c index 5822cb6..f58b69c 100644 --- a/api/session.c +++ b/api/session.c @@ -52,8 +52,7 @@ typedef struct _TUN_SESSION WINTUN_STATUS WINAPI WintunStartSession(_In_ const WINTUN_ADAPTER *Adapter, _In_ DWORD Capacity, _Out_ TUN_SESSION **Session) { - HANDLE Heap = GetProcessHeap(); - *Session = HeapAlloc(Heap, 0, sizeof(TUN_SESSION)); + *Session = HeapAlloc(ModuleHeap, 0, sizeof(TUN_SESSION)); if (!*Session) return LOG(WINTUN_LOG_ERR, L"Out of memory"), ERROR_OUTOFMEMORY; const ULONG RingSize = TUN_RING_SIZE(Capacity); @@ -113,7 +112,7 @@ cleanupSendTailMoved: cleanupAllocatedRegion: VirtualFree(AllocatedRegion, 0, MEM_RELEASE); cleanupRings: - HeapFree(Heap, 0, *Session); + HeapFree(ModuleHeap, 0, *Session); *Session = NULL; return Result; } @@ -126,7 +125,7 @@ WintunEndSession(_In_ TUN_SESSION *Session) CloseHandle(Session->Descriptor.Send.TailMoved); CloseHandle(Session->Descriptor.Receive.TailMoved); VirtualFree(Session->Descriptor.Send.Ring, 0, MEM_RELEASE); - HeapFree(GetProcessHeap(), 0, Session); + HeapFree(ModuleHeap, 0, Session); } BOOL WINAPI |