From 47dcc1dc50198385a975ef8d1fa35b3268dff8bd Mon Sep 17 00:00:00 2001 From: Meiguro Date: Sat, 13 Feb 2016 21:08:05 -0800 Subject: [PATCH] Fix SimplyMenu to free title only if it is not the empty title (Addresses #132) --- src/simply/simply_menu.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/simply/simply_menu.c b/src/simply/simply_menu.c index 09276f00..a8a05d07 100644 --- a/src/simply/simply_menu.c +++ b/src/simply/simply_menu.c @@ -161,13 +161,17 @@ static SimplyMenuSection *prv_get_menu_section(SimplyMenu *self, int index) { (void*)(uintptr_t) index); } +static void prv_free_title(char **title) { + if (*title && *title != EMPTY_TITLE) { + free(*title); + *title = NULL; + } +} + static void prv_destroy_section(SimplyMenu *self, SimplyMenuSection *section) { if (!section) { return; } list1_remove(&self->menu_layer.sections, §ion->node); - if (section->title && section->title != EMPTY_TITLE) { - free(section->title); - section->title = NULL; - } + prv_free_title(§ion->title); free(section); } @@ -187,14 +191,8 @@ static SimplyMenuItem *prv_get_menu_item(SimplyMenu *self, int section, int inde static void prv_destroy_item(SimplyMenu *self, SimplyMenuItem *item) { if (!item) { return; } list1_remove(&self->menu_layer.items, &item->node); - if (item->title) { - free(item->title); - item->title = NULL; - } - if (item->subtitle) { - free(item->subtitle); - item->subtitle = NULL; - } + prv_free_title(&item->title); + prv_free_title(&item->subtitle); free(item); }