wayland: close() the selection fd if we didn't start writing yet
authorCarlos Garnacho <carlosg@gnome.org>
Wed, 24 Jun 2015 19:52:23 +0000 (21:52 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Wed, 24 Jun 2015 21:52:50 +0000 (23:52 +0200)
If the other peer requests data too fast (too rare/unlikely though),
we might receive multiple gdk_wayland_selection_request_target() calls
with no ending gdk_wayland_selection_check_write(), in which case the
fd is leaked as no GOutputStream was created to take over it.

https://bugzilla.gnome.org/show_bug.cgi?id=751414

gdk/wayland/gdkselection-wayland.c

index 86bfde21a23ef8b322a56bc865ed22177ab27501..c5d0089579d0e75dc0af2374e66fb96e5570888a 100644 (file)
@@ -567,6 +567,13 @@ gdk_wayland_selection_request_target (GdkWaylandSelection *wayland_selection,
       wayland_selection->source_requested_target == target)
     return FALSE;
 
+  /* If we didn't issue gdk_wayland_selection_check_write() yet
+   * on a previous fd, it will still linger here. Just close it,
+   * as we can't have more than one fd on the fly.
+   */
+  if (wayland_selection->stored_selection.fd >= 0)
+    close (wayland_selection->stored_selection.fd);
+
   wayland_selection->stored_selection.fd = fd;
 
   wayland_selection->source_requested_target = target;