From bf4eabb4ca3fb1d0c68b375a2a964165776e44cb Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Sat, 24 Oct 2020 22:12:47 +0200 Subject: 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 --- api/session.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'api/session.c') 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 -- cgit v1.2.3-59-g8ed1b