From e86aa59a4dff8e9bd123ce73bfc6bb3d2e942a9d Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 31 Mar 2023 23:54:26 -0700 Subject: [PATCH] Fix memory leak in djui panel --- src/pc/djui/djui_panel.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pc/djui/djui_panel.c b/src/pc/djui/djui_panel.c index 5921aaaf..8c5effdc 100644 --- a/src/pc/djui/djui_panel.c +++ b/src/pc/djui/djui_panel.c @@ -42,7 +42,6 @@ struct DjuiPanel* djui_panel_add(struct DjuiBase* caller, struct DjuiThreePanel* // calculate 3panel body height djui_three_panel_recalculate_body_size(threePanel); - // allocate panel struct DjuiPanel* panel = calloc(1, sizeof(struct DjuiPanel)); panel->parent = sPanelList; @@ -149,17 +148,21 @@ void djui_panel_update(void) { if (panel->on_panel_destroy) { panel->on_panel_destroy(NULL); } + if (activeBase == removingBase) { activeBase = NULL; } + if (parentBase == removingBase) { parentBase = NULL; } djui_base_destroy(removingBase); free(panel); + removingBase = NULL; + return; } } - if (removingBase != NULL) { + if (activeBase && removingBase) { activeBase->y.value = moveMax - moveMax * smoothstep(0, moveMax, sMoveAmount); - if (sPanelRemoving != NULL) { + if (sPanelRemoving) { removingBase->y.value = activeBase->y.value - 1.0f; } - } else if (parentBase != NULL) { + } else if (activeBase && parentBase) { activeBase->y.value = moveMax * smoothstep(0, moveMax, sMoveAmount) - moveMax; parentBase->y.value = activeBase->y.value + moveMax; }