diff --git a/windows/init.c b/windows/init.c index 9539cf4d..60b60f2f 100644 --- a/windows/init.c +++ b/windows/init.c @@ -107,7 +107,7 @@ const char *uiInit(uiInitOptions *o) void uiUninit(void) { - // TODO free menus + uninitMenus(); // TODO delete hollow brush // TODO uninit container // TODO delete message font diff --git a/windows/menu.c b/windows/menu.c index 92e46850..341f7fb9 100644 --- a/windows/menu.c +++ b/windows/menu.c @@ -351,3 +351,30 @@ void freeMenubar(HMENU menubar) } // no need to worry about destroying any menus; destruction of the window they're in will do it for us } + +void uninitMenus(void) +{ + struct menu *m; + struct menuItem *item; + uintmax_t i, j; + + for (i = 0; i < len; i++) { + m = menus[i]; + uiFree(m->name); + for (j = 0; j < m->len; j++) { + item = m->items[j]; + if (item->len != 0) + complain("menu item %p (%ws) still has uiWindows attached; did you forget to free some?", item, item->name); + if (item->name != NULL) + uiFree(item->name); + if (item->hmenus != NULL) + uiFree(item->hmenus); + uiFree(item); + } + if (m->items != NULL) + uiFree(m->items); + uiFree(m); + } + if (menus != NULL) + uiFree(menus); +} diff --git a/windows/uipriv_windows.h b/windows/uipriv_windows.h index 0cdd2285..f6ff8643 100644 --- a/windows/uipriv_windows.h +++ b/windows/uipriv_windows.h @@ -82,6 +82,7 @@ extern HMENU makeMenubar(void); extern const uiMenuItem *menuIDToItem(UINT_PTR); extern void runMenuEvent(WORD, uiWindow *); extern void freeMenubar(HMENU); +extern void uninitMenus(void); // alloc.c extern int initAlloc(void);