From 696609720390bfb5443c839587f42c288c01552e Mon Sep 17 00:00:00 2001
From: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Date: Sat, 21 Nov 2026 18:19:09 -0800
Subject: [PATCH] gtk4(x): Leave closing a gui_dialog window to its response
 callback

The close-request handler emitted the delete response and then let
gtk destroy the window. The diplomacy dialogs only ask the server to
cancel on that response, so the window and the gui_dialog were gone
while the meeting, and the owner's pointer to the dialog, lived on;
the server's cancel then destroyed the freed dialog again. Every
other response callback destroys the dialog itself.

Return TRUE, as a tab's close button and Escape already behave, so
that a gui_dialog is destroyed only through gui_dialog_destroy().

See RM #2498

Signed-off-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
---
 client/gui-gtk-4.0/gui_stuff.c | 8 +++++---
 client/gui-gtk-5.0/gui_stuff.c | 8 +++++---
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/client/gui-gtk-4.0/gui_stuff.c b/client/gui-gtk-4.0/gui_stuff.c
index cd6d4c0a02..dd6ed41d1f 100644
--- a/client/gui-gtk-4.0/gui_stuff.c
+++ b/client/gui-gtk-4.0/gui_stuff.c
@@ -341,11 +341,13 @@ static gint gui_dialog_delete_handler(GtkWidget *widget, gpointer data)
 {
   struct gui_dialog *dlg = data;
 
-  /* emit response signal. */
+  /* Emit response signal. */
   gui_dialog_response(dlg, GTK_RESPONSE_DELETE_EVENT);
 
-  /* do the destroy by default. */
-  return FALSE;
+  /* Never let gtk destroy the window. As with a tab, the response
+   * callback decides, and destroys the dialog with gui_dialog_destroy()
+   * so the owner's pointer is cleared. */
+  return TRUE;
 }
 
 /**********************************************************************//**
diff --git a/client/gui-gtk-5.0/gui_stuff.c b/client/gui-gtk-5.0/gui_stuff.c
index 41bbfb53c0..47589929a6 100644
--- a/client/gui-gtk-5.0/gui_stuff.c
+++ b/client/gui-gtk-5.0/gui_stuff.c
@@ -342,11 +342,13 @@ static gint gui_dialog_delete_handler(GtkWidget *widget, gpointer data)
 {
   struct gui_dialog *dlg = data;
 
-  /* emit response signal. */
+  /* Emit response signal. */
   gui_dialog_response(dlg, GTK_RESPONSE_DELETE_EVENT);
 
-  /* do the destroy by default. */
-  return FALSE;
+  /* Never let gtk destroy the window. As with a tab, the response
+   * callback decides, and destroys the dialog with gui_dialog_destroy()
+   * so the owner's pointer is cleared. */
+  return TRUE;
 }
 
 /**********************************************************************//**
-- 
2.55.0

