diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index ebfaedb0a..1b054449e 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -903,12 +903,9 @@ del_widget (void *w) if (d == h->current) dlg_set_current_widget_next (h); - h->widgets = g_list_remove_link (h->widgets, d); + h->widgets = g_list_delete_link (h->widgets, d); if (h->widgets == NULL) h->current = NULL; - send_message (d->data, NULL, MSG_DESTROY, 0, NULL); - g_free (d->data); - g_list_free_1 (d); /* widget has been deleted in runtime */ if (widget_get_state (WIDGET (h), WST_ACTIVE)) @@ -916,6 +913,8 @@ del_widget (void *w) dlg_redraw (h); dlg_select_current_widget (h); } + + WIDGET (w)->owner = NULL; } /* --------------------------------------------------------------------------------------------- */ @@ -1177,8 +1176,8 @@ dlg_destroy (WDialog * h) { /* if some widgets have history, save all history at one moment here */ dlg_save_history (h); - dlg_broadcast_msg (h, MSG_DESTROY); - g_list_free_full (h->widgets, g_free); + g_list_foreach (h->widgets, (GFunc) widget_destroy, NULL); + g_list_free (h->widgets); mc_event_group_del (h->event_group); g_free (h->event_group); g_free (h->title); diff --git a/lib/widget/widget-common.c b/lib/widget/widget-common.c index f1e263c16..5e093f41d 100644 --- a/lib/widget/widget-common.c +++ b/lib/widget/widget-common.c @@ -215,6 +215,15 @@ widget_init (Widget * w, int y, int x, int lines, int cols, /* --------------------------------------------------------------------------------------------- */ +void +widget_destroy (Widget * w) +{ + send_message (w, NULL, MSG_DESTROY, 0, NULL); + g_free (w); +} + +/* --------------------------------------------------------------------------------------------- */ + /* Default callback for widgets */ cb_ret_t widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) diff --git a/lib/widget/widget-common.h b/lib/widget/widget-common.h index 5ce18ad57..c6573a51c 100644 --- a/lib/widget/widget-common.h +++ b/lib/widget/widget-common.h @@ -175,6 +175,7 @@ void hotkey_draw (Widget * w, const hotkey_t hotkey, gboolean focused); /* widget initialization */ void widget_init (Widget * w, int y, int x, int lines, int cols, widget_cb_fn callback, widget_mouse_cb_fn mouse_callback); +void widget_destroy (Widget * w); /* Default callback for widgets */ cb_ret_t widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data); diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 24bafab0f..b34ee0601 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -2268,6 +2268,7 @@ edit_close_cmd (WEdit * edit) unlock_file (edit->filename_vpath); del_widget (edit); + widget_destroy (WIDGET (edit)); if (edit_widget_is_editor (CONST_WIDGET (h->current->data))) edit = (WEdit *) h->current->data; diff --git a/src/filemanager/filegui.c b/src/filemanager/filegui.c index 5e3e41822..6086a7237 100644 --- a/src/filemanager/filegui.c +++ b/src/filemanager/filegui.c @@ -904,8 +904,7 @@ file_op_context_create_ui (file_op_context_t * ctx, gboolean with_eta, progress_buttons[2].text, progress_button_callback)); progress_buttons[2].len = button_get_len (BUTTON (progress_buttons[2].w)); - send_message (progress_buttons[2].w, NULL, MSG_DESTROY, 0, NULL); - g_free (progress_buttons[2].w); + widget_destroy (progress_buttons[2].w); } progress_buttons[2].w = progress_buttons[1].w;