From 38010ce65ec6d573da84819a57a2597169be948a Mon Sep 17 00:00:00 2001 From: CTCaer Date: Thu, 19 May 2022 15:14:05 +0300 Subject: [PATCH] nyx: utilize ini free and fix various memleaks With the new changes the heap and heap node usage drops 95% on boot. Subsequent accesses to Launch/More config keep the counter the same. --- nyx/nyx_gui/config.c | 2 ++ nyx/nyx_gui/frontend/fe_emummc_tools.c | 2 ++ nyx/nyx_gui/frontend/gui.c | 13 +++++-------- nyx/nyx_gui/frontend/gui_emummc_tools.c | 1 + nyx/nyx_gui/frontend/gui_info.c | 1 + nyx/nyx_gui/frontend/gui_options.c | 4 ++++ nyx/nyx_gui/nyx.c | 4 ++++ 7 files changed, 19 insertions(+), 8 deletions(-) diff --git a/nyx/nyx_gui/config.c b/nyx/nyx_gui/config.c index 0fa10b3..3d6e368 100644 --- a/nyx/nyx_gui/config.c +++ b/nyx/nyx_gui/config.c @@ -169,6 +169,8 @@ int create_config_entry() break; } } + + ini_free(&ini_sections); } f_close(&fp); diff --git a/nyx/nyx_gui/frontend/fe_emummc_tools.c b/nyx/nyx_gui/frontend/fe_emummc_tools.c index e6b2869..496bd2a 100644 --- a/nyx/nyx_gui/frontend/fe_emummc_tools.c +++ b/nyx/nyx_gui/frontend/fe_emummc_tools.c @@ -66,6 +66,8 @@ void load_emummc_cfg(emummc_cfg_t *emu_info) break; } } + + ini_free(&ini_sections); } void save_emummc_cfg(u32 part_idx, u32 sector_start, const char *path) diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c index 324c6cf..01df422 100644 --- a/nyx/nyx_gui/frontend/gui.c +++ b/nyx/nyx_gui/frontend/gui.c @@ -1378,14 +1378,10 @@ static lv_res_t _create_mbox_payloads(lv_obj_t *btn) goto out_end; } - char *dir = (char *)malloc(256); - strcpy(dir, "bootloader/payloads"); - - char *filelist = dirlist(dir, NULL, false, false); + char *filelist = dirlist("bootloader/payloads", NULL, false, false); sd_unmount(); u32 i = 0; - if (filelist) { while (true) @@ -1395,6 +1391,7 @@ static lv_res_t _create_mbox_payloads(lv_obj_t *btn) lv_list_add(list, NULL, &filelist[i * 256], launch_payload); i++; } + free(filelist); } out_end: @@ -1703,9 +1700,7 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn) if (combined_cfg && !ini_parse_success) { ini_parsing: - // Reinit list. - ini_sections.prev = &ini_sections; - ini_sections.next = &ini_sections; + list_init(&ini_sections); ini_parse_success = ini_parse(&ini_sections, "bootloader/ini", true); more_cfg = true; } @@ -1851,6 +1846,8 @@ ini_parsing: break; } + ini_free(&ini_sections); + ini_parse_failed: // Reiterate the loop with more cfgs if combined. if (combined_cfg && (curr_btn_idx < (n_cfg.entries_5_columns ? 10 : 8)) && !more_cfg) diff --git a/nyx/nyx_gui/frontend/gui_emummc_tools.c b/nyx/nyx_gui/frontend/gui_emummc_tools.c index 9443966..56d19ff 100644 --- a/nyx/nyx_gui/frontend/gui_emummc_tools.c +++ b/nyx/nyx_gui/frontend/gui_emummc_tools.c @@ -1114,6 +1114,7 @@ out0:; lv_label_set_text(lv_desc, txt_buf); lv_obj_align(lv_desc, btn, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 5); } + free(txt_buf); // Create SD File Based container. lv_obj_t *h2 = lv_cont_create(win, NULL); diff --git a/nyx/nyx_gui/frontend/gui_info.c b/nyx/nyx_gui/frontend/gui_info.c index 7d90e75..5b63d93 100644 --- a/nyx/nyx_gui/frontend/gui_info.c +++ b/nyx/nyx_gui/frontend/gui_info.c @@ -56,6 +56,7 @@ static lv_res_t _create_window_dump_done(int error, char *dump_filenames) s_printf(txt_buf, "Dumping to SD card finished!\nFiles: #C7EA46 backup/%s/dumps/#\n%s", sn, dump_filenames); } lv_mbox_set_text(mbox, txt_buf); + free(txt_buf); lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); // Important. After set_text. diff --git a/nyx/nyx_gui/frontend/gui_options.c b/nyx/nyx_gui/frontend/gui_options.c index 297ac63..b749e48 100644 --- a/nyx/nyx_gui/frontend/gui_options.c +++ b/nyx/nyx_gui/frontend/gui_options.c @@ -237,6 +237,8 @@ static void _create_autoboot_window() lv_list_add(list_main, NULL, ini_sec->name, _autoboot_enable_main_action); } + + ini_free(&ini_sections); } // More configuration container. @@ -279,6 +281,8 @@ static void _create_autoboot_window() lv_list_add(list_more_cfg, NULL, ini_sec->name, _autoboot_enable_more_action); } + + ini_free(&ini_list_sections); } sd_unmount(); diff --git a/nyx/nyx_gui/nyx.c b/nyx/nyx_gui/nyx.c index ba73e92..32ae2a3 100644 --- a/nyx/nyx_gui/nyx.c +++ b/nyx/nyx_gui/nyx.c @@ -247,6 +247,8 @@ void load_saved_configuration() } } + ini_free(&ini_sections); + skip_main_cfg_parse: if (!ini_parse(&ini_nyx_sections, "bootloader/nyx.ini", false)) return; @@ -282,6 +284,8 @@ skip_main_cfg_parse: break; } } + + ini_free(&ini_nyx_sections); } #define EXCP_EN_ADDR 0x4003FFFC