From 20f55290ca0f97925935467e8ddc8f80e19ec5ab Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 29 Nov 2023 17:44:54 +0100
Subject: [PATCH] creatediskimage: Fix crash if image creation has errors

The change to use the dialogue "response" signal made the code release
the last reference to the DialogData before the user could answer, and
when they did, we would crash trying to access it.

Fixes: 6ef5a055debd ("creatediskimage: Use dialog response signal")
Closes: #319

---
 src/disks/gducreatediskimagedialog.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/disks/gducreatediskimagedialog.c b/src/disks/gducreatediskimagedialog.c
index 5f64c81..5d5a4d9 100644
--- a/src/disks/gducreatediskimagedialog.c
+++ b/src/disks/gducreatediskimagedialog.c
@@ -466,6 +466,7 @@ on_response (GtkDialog  *dialog,
           g_clear_error (&error);
         }
     }
+  dialog_data_unref (data);
 }
 
 static gboolean
@@ -514,7 +515,7 @@ on_success (gpointer user_data)
                              GTK_RESPONSE_NO);
       gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Close"), GTK_RESPONSE_CLOSE);
       gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
-      g_signal_connect (dialog, "response", G_CALLBACK (on_response), data);
+      g_signal_connect (dialog, "response", G_CALLBACK (on_response), dialog_data_ref (data));
       g_free (s);
 
       gtk_window_present (GTK_WINDOW (dialog));
-- 
2.27.0

