diff --git a/windows/alloc.c b/windows/alloc.c index 302229f5..fe113193 100644 --- a/windows/alloc.c +++ b/windows/alloc.c @@ -23,6 +23,34 @@ int initAlloc(void) #define CCHAR(p) ((const char **) (p)) #define TYPE(p) CCHAR(UINT8(p)) +void uninitAlloc(void) +{ + BOOL hasEntry; + PROCESS_HEAP_ENTRY phe; + DWORD le; + + hasEntry = FALSE; + ZeroMemory(&phe, sizeof (PROCESS_HEAP_ENTRY)); + while (HeapWalk(heap, &phe) != 0) { + // skip non-allocations + if ((phe.wFlags & PROCESS_HEAP_ENTRY_BUSY) == 0) + continue; + if (!hasEntry) { + fprintf(stderr, "[libui] leaked allocations:\n"); + hasEntry = TRUE; + } + fprintf(stderr, "[libui] %p %s\n", phe.lpData, *TYPE(phe.lpData)); + } + le = GetLastError(); + SetLastError(le); // just in case + if (le != ERROR_NO_MORE_ITEMS) + logLastError("error walking heap in uninitAlloc()"); + if (hasEntry) + complain("either you left something around or there's a bug in libui"); + if (HeapDestroy(heap) == 0) + logLastError("error destroying heap in uninitAlloc()"); +} + void *uiAlloc(size_t size, const char *type) { void *out; diff --git a/windows/init.c b/windows/init.c index dc679ba1..9539cf4d 100644 --- a/windows/init.c +++ b/windows/init.c @@ -114,7 +114,7 @@ void uiUninit(void) // TODO uninit window // TODO delete default cursor // TODO delete default icon - // TODO uninit alloc + uninitAlloc(); } void uiFreeInitError(const char *err) diff --git a/windows/uipriv_windows.h b/windows/uipriv_windows.h index 1911c1b2..0cdd2285 100644 --- a/windows/uipriv_windows.h +++ b/windows/uipriv_windows.h @@ -85,6 +85,7 @@ extern void freeMenubar(HMENU); // alloc.c extern int initAlloc(void); +extern void uninitAlloc(void); // tab.c extern void tabEnterTabNavigation(HWND);