[mutter/gnome-3-34] x11: Detach selection streams on dispose



commit 4d0a331cfe0930de38d901cd20d1b0634eeb9f58
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Oct 21 11:40:41 2019 +0200

    x11: Detach selection streams on dispose
    
    The streams were only detached from MetaX11Display (and its event handling)
    on completion. This is too much to expect, and those might be in some
    circumstances replaced while operating.
    
    Make those streams detach themselves on dispose(), so we don't trip into
    freed memory later on when trying to dispatch unrelated X11 selection events.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/869
    (cherry picked from commit e1fa0734a9985c06b5a9cbd031d3563ad463904b)

 src/x11/meta-x11-selection-input-stream.c  | 15 +++++++++++++++
 src/x11/meta-x11-selection-output-stream.c | 15 +++++++++++++++
 2 files changed, 30 insertions(+)
---
diff --git a/src/x11/meta-x11-selection-input-stream.c b/src/x11/meta-x11-selection-input-stream.c
index 44309ba98..e8d782047 100644
--- a/src/x11/meta-x11-selection-input-stream.c
+++ b/src/x11/meta-x11-selection-input-stream.c
@@ -261,6 +261,20 @@ meta_x11_selection_input_stream_close_finish (GInputStream  *stream,
   return TRUE;
 }
 
+static void
+meta_x11_selection_input_stream_dispose (GObject *object)
+{
+  MetaX11SelectionInputStream *stream =
+    META_X11_SELECTION_INPUT_STREAM (object);
+  MetaX11SelectionInputStreamPrivate *priv =
+    meta_x11_selection_input_stream_get_instance_private (stream);
+
+  priv->x11_display->selection.input_streams =
+    g_list_remove (priv->x11_display->selection.input_streams, stream);
+
+  G_OBJECT_CLASS (meta_x11_selection_input_stream_parent_class)->dispose (object);
+}
+
 static void
 meta_x11_selection_input_stream_finalize (GObject *object)
 {
@@ -284,6 +298,7 @@ meta_x11_selection_input_stream_class_init (MetaX11SelectionInputStreamClass *kl
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GInputStreamClass *istream_class = G_INPUT_STREAM_CLASS (klass);
 
+  object_class->dispose = meta_x11_selection_input_stream_dispose;
   object_class->finalize = meta_x11_selection_input_stream_finalize;
 
   istream_class->read_fn = meta_x11_selection_input_stream_read;
diff --git a/src/x11/meta-x11-selection-output-stream.c b/src/x11/meta-x11-selection-output-stream.c
index 723903835..86615364a 100644
--- a/src/x11/meta-x11-selection-output-stream.c
+++ b/src/x11/meta-x11-selection-output-stream.c
@@ -489,6 +489,20 @@ meta_x11_selection_output_stream_close_finish (GOutputStream  *stream,
   return g_task_propagate_boolean (G_TASK (result), error);
 }
 
+static void
+meta_x11_selection_output_stream_dispose (GObject *object)
+{
+  MetaX11SelectionOutputStream *stream =
+    META_X11_SELECTION_OUTPUT_STREAM (object);
+  MetaX11SelectionOutputStreamPrivate *priv =
+    meta_x11_selection_output_stream_get_instance_private (stream);
+
+  priv->x11_display->selection.output_streams =
+    g_list_remove (priv->x11_display->selection.output_streams, stream);
+
+  G_OBJECT_CLASS (meta_x11_selection_output_stream_parent_class)->dispose (object);
+}
+
 static void
 meta_x11_selection_output_stream_finalize (GObject *object)
 {
@@ -514,6 +528,7 @@ meta_x11_selection_output_stream_class_init (MetaX11SelectionOutputStreamClass *
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GOutputStreamClass *output_stream_class = G_OUTPUT_STREAM_CLASS (klass);
 
+  object_class->dispose = meta_x11_selection_output_stream_dispose;
   object_class->finalize = meta_x11_selection_output_stream_finalize;
 
   output_stream_class->write_fn = meta_x11_selection_output_stream_write;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]