diff --git a/menu/menu_entries.c b/menu/menu_entries.c index ff893aad4d..05d4b69707 100644 --- a/menu/menu_entries.c +++ b/menu/menu_entries.c @@ -62,29 +62,40 @@ static void menu_list_free_list(file_list_t *list) static void menu_list_free(menu_list_t *menu_list) { - unsigned i; if (!menu_list) return; - for (i = 0; i < menu_list->menu_stack_size; i++) + if (menu_list->menu_stack) { - if (!menu_list->menu_stack[i]) - continue; + unsigned i; - menu_list_free_list(menu_list->menu_stack[i]); - menu_list->menu_stack[i] = NULL; - } - for (i = 0; i < menu_list->selection_buf_size; i++) - { - if (!menu_list->selection_buf[i]) - continue; + for (i = 0; i < menu_list->menu_stack_size; i++) + { + if (!menu_list->menu_stack[i]) + continue; - menu_list_free_list(menu_list->selection_buf[i]); - menu_list->selection_buf[i] = NULL; + menu_list_free_list(menu_list->menu_stack[i]); + menu_list->menu_stack[i] = NULL; + } + + free(menu_list->menu_stack); } - free(menu_list->menu_stack); - free(menu_list->selection_buf); + if (menu_list->selection_buf) + { + unsigned i; + + for (i = 0; i < menu_list->selection_buf_size; i++) + { + if (!menu_list->selection_buf[i]) + continue; + + menu_list_free_list(menu_list->selection_buf[i]); + menu_list->selection_buf[i] = NULL; + } + + free(menu_list->selection_buf); + } free(menu_list); }