From 7513fd5d6440a87c290f61455a2c355ed200073a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 30 May 2023 17:59:06 +0200 Subject: [PATCH] gdkselectioninputstream-x11: Explicitly handle stream ownership in signal The display xevent signal connection takes the ownership of the stream until we get a valid event, so it should manage the stream lifetime. So make this clearer, by automatically removing the stream reference when we disconnect from the xevent signal handler. --- gdk/x11/gdkselectioninputstream-x11.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gdk/x11/gdkselectioninputstream-x11.c b/gdk/x11/gdkselectioninputstream-x11.c index e62bd96035..6682639f44 100644 --- a/gdk/x11/gdkselectioninputstream-x11.c +++ b/gdk/x11/gdkselectioninputstream-x11.c @@ -165,9 +165,7 @@ gdk_x11_selection_input_stream_complete (GdkX11SelectionInputStream *stream) GDK_X11_DISPLAY (priv->display)->streams = g_slist_remove (GDK_X11_DISPLAY (priv->display)->streams, stream); g_signal_handlers_disconnect_by_func (priv->display, gdk_x11_selection_input_stream_xevent, - stream); - - g_object_unref (stream); + g_steal_pointer (&stream)); } static gssize @@ -541,7 +539,10 @@ gdk_x11_selection_input_stream_new_async (GdkDisplay *display, priv->property = g_strdup_printf ("GDK_SELECTION_%p", stream); priv->xproperty = gdk_x11_get_xatom_by_name_for_display (display, priv->property); - g_signal_connect (display, "xevent", G_CALLBACK (gdk_x11_selection_input_stream_xevent), stream); + g_signal_connect_data (display, "xevent", + G_CALLBACK (gdk_x11_selection_input_stream_xevent), + g_steal_pointer (&stream), + (GClosureNotify) g_object_unref, 0); XConvertSelection (GDK_DISPLAY_XDISPLAY (display), priv->xselection, -- 2.30.2