diff --git a/src/terminal/widget.c b/src/terminal/widget.c index eebec1b..82e4e2a 100644 --- a/src/terminal/widget.c +++ b/src/terminal/widget.c @@ -184,6 +184,18 @@ static void v3270_toggle_changed(G_GNUC_UNUSED v3270 *widget, G_GNUC_UNUSED LIB3 { } +static gboolean delayed_cleanup(H3270 *hSession) { + + if(lib3270_get_task_count(hSession)) + return G_SOURCE_CONTINUE; + + g_message("Delayed cleanup complete"); + lib3270_free(hSession); + + return G_SOURCE_REMOVE; + +} + static void finalize(GObject *object) { debug("V3270::%s",__FUNCTION__); @@ -196,13 +208,18 @@ static void finalize(GObject *object) { lib3270_disconnect(terminal->host); debug("Task count: %u",lib3270_get_task_count(terminal->host)); - while(lib3270_get_task_count(terminal->host)) + if(lib3270_get_task_count(terminal->host)) + { + // Should wait. + g_message("TN3270 session is busy, delaying cleanup"); + lib3270_set_user_data(terminal->host,NULL); + g_idle_add((GSourceFunc) delayed_cleanup,terminal->host); + } + else { - debug("%s: waiting",__FUNCTION__); - usleep(100); + lib3270_session_free(terminal->host); } - lib3270_session_free(terminal->host); terminal->host = NULL; } @@ -608,6 +625,8 @@ static void v3270_destroy(GtkWidget *widget) // Cleanup lib3270_reset_callbacks(terminal->host); lib3270_set_user_data(terminal->host,NULL); + + debug("%s: disconnecting", __FUNCTION__); lib3270_disconnect(terminal->host); } -- libgit2 0.21.2