summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-03-13 10:37:20 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-04-10 11:18:25 +0800
commit37bff93c8b0a71432613f41f2319dc073ca64619 (patch)
tree54f43ede1083c596a68864a534dd87cc6237ba2d
parent1bbd230d618162ccd5ea97540a413c766a07c0cb (diff)
downloadtalos-petitboot-37bff93c8b0a71432613f41f2319dc073ca64619.tar.gz
talos-petitboot-37bff93c8b0a71432613f41f2319dc073ca64619.zip
ui/ncurses: Use pmenu_item destrutor to free ncurses ITEMs
Currently, pemnu_destroy is used to free items. This means that the menu code needs to iterate over items, and we have no way to free the ITEM * of items that aren't in a menu. Instead, free the ITEM in the pmenu_item destructor. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r--ui/ncurses/nc-menu.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/ui/ncurses/nc-menu.c b/ui/ncurses/nc-menu.c
index 5691f42..745c1ff 100644
--- a/ui/ncurses/nc-menu.c
+++ b/ui/ncurses/nc-menu.c
@@ -76,6 +76,13 @@ static void pmenu_resize(struct nc_scr *scr)
pmenu_post(scr);
}
+static int pmenu_item_destructor(void *arg)
+{
+ struct pmenu_item *item = arg;
+ free_item(item->nci);
+ return 0;
+}
+
/**
* pmenu_item_create - Allocate and initialize a new pmenu_item instance.
*
@@ -96,6 +103,8 @@ struct pmenu_item *pmenu_item_create(struct pmenu *menu, const char *name)
return NULL;
}
+ talloc_set_destructor(item, pmenu_item_destructor);
+
set_item_userptr(item->nci, item);
return item;
@@ -270,7 +279,6 @@ int pmenu_remove(struct pmenu *menu, struct pmenu_item *item)
if (index < 0)
return -1;
- free_item(item->nci);
talloc_free(item);
/* Note that items array has a null terminator. */
@@ -356,14 +364,9 @@ int pmenu_setup(struct pmenu *menu)
void pmenu_delete(struct pmenu *menu)
{
- unsigned int i;
-
assert(menu->scr.sig == pb_pmenu_sig);
menu->scr.sig = pb_removed_sig;
- for (i = item_count(menu->ncm); i; i--)
- free_item(menu->items[i - 1]);
-
free_menu(menu->ncm);
delwin(menu->scr.sub_ncw);
delwin(menu->scr.main_ncw);
OpenPOWER on IntegriCloud