gtkdnd: Keep a reference on destination drag context

If we don't keep a reference on it, it is released somewhere before
gtk_drag_abort_timeout is called. This can cause a crash e.g. when the
dnd takes place in the GtkSocket/GtkPlug framework.

Fixes: #7128
This commit is contained in:
Gaël Bonithon 2023-12-10 10:17:00 +01:00
parent 2353a7a176
commit 34c12e4885

View File

@ -2666,6 +2666,8 @@ gtk_drag_drop (GtkDragSourceInfo *info,
{ {
if (info->icon_window) if (info->icon_window)
gtk_widget_hide (info->icon_window); gtk_widget_hide (info->icon_window);
if (info->proxy_dest)
g_object_ref (info->proxy_dest->context);
gdk_drag_drop (info->context, time); gdk_drag_drop (info->context, time);
info->drop_timeout = gdk_threads_add_timeout (DROP_ABORT_TIME, info->drop_timeout = gdk_threads_add_timeout (DROP_ABORT_TIME,
@ -2814,7 +2816,11 @@ gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
gtk_target_list_unref (info->target_list); gtk_target_list_unref (info->target_list);
if (info->drop_timeout) if (info->drop_timeout)
{
g_source_remove (info->drop_timeout); g_source_remove (info->drop_timeout);
if (info->proxy_dest)
g_object_unref (info->proxy_dest->context);
}
if (info->update_idle) if (info->update_idle)
g_source_remove (info->update_idle); g_source_remove (info->update_idle);
@ -3260,14 +3266,20 @@ static gboolean
gtk_drag_abort_timeout (gpointer data) gtk_drag_abort_timeout (gpointer data)
{ {
GtkDragSourceInfo *info = data; GtkDragSourceInfo *info = data;
GdkDragContext *context = NULL;
guint32 time = GDK_CURRENT_TIME; guint32 time = GDK_CURRENT_TIME;
if (info->proxy_dest) if (info->proxy_dest)
{
time = info->proxy_dest->proxy_drop_time; time = info->proxy_dest->proxy_drop_time;
context = info->proxy_dest->context;
}
info->drop_timeout = 0; info->drop_timeout = 0;
gtk_drag_drop_finished (info, GTK_DRAG_RESULT_TIMEOUT_EXPIRED, time); gtk_drag_drop_finished (info, GTK_DRAG_RESULT_TIMEOUT_EXPIRED, time);
g_clear_object (&context);
return FALSE; return FALSE;
} }