[PATCH 2/2] ui: Fix curses menu item label leak

Nicholas Piggin npiggin at gmail.com
Tue Feb 6 00:02:09 AEDT 2024


When a menu item name is updated, the old label is not freed.

Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
 ui/ncurses/nc-menu.c | 4 ++++
 ui/ncurses/nc-menu.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/ui/ncurses/nc-menu.c b/ui/ncurses/nc-menu.c
index a1524b5..70f2210 100644
--- a/ui/ncurses/nc-menu.c
+++ b/ui/ncurses/nc-menu.c
@@ -82,6 +82,7 @@ static void pmenu_resize(struct nc_scr *scr)
 static int pmenu_item_destructor(void *arg)
 {
 	struct pmenu_item *item = arg;
+	talloc_free((char *)item->label);
 	free_item(item->nci);
 	return 0;
 }
@@ -146,7 +147,9 @@ int pmenu_item_update(struct pmenu_item *item, const char *name)
 		talloc_free((char *)label);
 		return -1;
 	}
+	talloc_free((char *)item->label);
 	free_item(item->nci);
+	item->label = label;
 	item->nci = i;
 
 	return 0;
@@ -168,6 +171,7 @@ struct pmenu_item *pmenu_item_create(struct pmenu *menu, const char *name)
 
 	item->i_sig = pb_item_sig;
 	item->pmenu = menu;
+	item->label = label;
 	item->nci = new_item(label, NULL);
 
 	if (!item->nci) {
diff --git a/ui/ncurses/nc-menu.h b/ui/ncurses/nc-menu.h
index 550c7e1..7ba45bf 100644
--- a/ui/ncurses/nc-menu.h
+++ b/ui/ncurses/nc-menu.h
@@ -46,6 +46,7 @@ struct pmenu;
 
 struct pmenu_item {
 	enum pb_nc_sig i_sig;
+	const char *label;
 	ITEM *nci;
 	struct pmenu *pmenu;
 	void *data;
-- 
2.42.0



More information about the Petitboot mailing list