[polari/wip/fmuellner/invalid-object-access: 7/10] roomList: Disconnect channel signals



commit 6c78343307e33de2bdd8c156601090bb44727da2
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Dec 6 01:14:45 2017 +0100

    roomList: Disconnect channel signals
    
    When leaving a room, the corresponding row is destroyed immediately to
    respond to the user action as fast as possible; actually disconnecting
    from the room can take a bit longer, so its quite possible for a channel
    to outlive the row, so we need to disconnect any signals to avoid access
    to invalidated objects.
    
    https://gitlab.gnome.org/GNOME/polari/issues/32

 src/roomList.js | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/src/roomList.js b/src/roomList.js
index 514636c..f7dc284 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -51,6 +51,9 @@ var RoomRow = GObject.registerClass({
 
         this.connect('destroy', () => {
             room.disconnect(channelChangedId);
+            this._channelSignals.forEach(id => {
+                room.channel.disconnect(id);
+            });
             if (connectionStatusChangedId)
                 this.account.disconnect(connectionStatusChangedId);
         });
@@ -128,13 +131,17 @@ var RoomRow = GObject.registerClass({
     }
 
     _onChannelChanged() {
+        this._channelSignals = [];
+
         if (!this._room.channel)
             return;
         this._eventStack.visible_child_name = 'messages';
-        this._room.channel.connect('message-received',
-                                   this._updatePending.bind(this));
-        this._room.channel.connect('pending-message-removed',
-                                   this._updatePending.bind(this));
+
+        for (let signal of ['message-received', 'pending-message-removed'])
+            this._channelSignals.push(
+                this._room.channel.connect(signal,
+                                           this._updatePending.bind(this))
+            );
         this._updatePending();
     }
 


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