gdkselectioninputstream-x11: Explicitly handle stream ownership in signal
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Tue, 30 May 2023 15:59:06 +0000 (17:59 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 5 Jun 2023 12:01:55 +0000 (08:01 -0400)
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

index e62bd96035915de95c6317ca31326ff5d4ed6b80..6682639f44f6157401705f146bacd08f92bc6eaa 100644 (file)
@@ -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,