[gnome-maps/gnome-42] application: Dispose contact store on window destroy



commit a9de57ebb6132b350a0109102f5f686a85079481
Author: Marcus Lundblad <ml dfupdate se>
Date:   Mon Jun 20 19:21:08 2022 +0200

    application: Dispose contact store on window destroy
    
    When quitting through closing the window, the contact
    store is disposed in the final GJS GC sweep, which
    seems to cause some race condition with respect to
    the main loop.
    As a workaround to this, manually dispose the store
    in this callback, and set it to null.
    Also guard some calls involving contact store with
    nullish checks to avoid possible use-after-free.
    
    Cherry-picked from !229

 src/application.js | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 0e2e65e5..9f49ee51 100644
--- a/src/application.js
+++ b/src/application.js
@@ -152,7 +152,7 @@ var Application = GObject.registerClass({
     }
 
     _showContact(id) {
-        contactStore.lookup(id, (contact) => {
+        contactStore?.lookup(id, (contact) => {
             this.mark_busy();
             if (!contact) {
                 this.unmark_busy();
@@ -172,13 +172,15 @@ var Application = GObject.registerClass({
 
         let id = parameter.deep_unpack();
 
-        if (contactStore.state === Maps.ContactStoreState.LOADED) {
-            this. _showContact(id);
-        } else {
-            Utils.once(contactStore, 'notify::state', () => {
-                if (contactStore.state === Maps.ContactStoreState.LOADED)
-                    this._showContact(id);
-            });
+        if (contactStore) {
+            if (contactStore.state === Maps.ContactStoreState.LOADED) {
+                this. _showContact(id);
+            } else {
+                Utils.once(contactStore, 'notify::state', () => {
+                    if (contactStore.state === Maps.ContactStoreState.LOADED)
+                        this._showContact(id);
+                });
+            }
         }
     }
 
@@ -204,9 +206,11 @@ var Application = GObject.registerClass({
     }
 
     _addContacts() {
-        let contacts = contactStore.get_contacts();
+        if (contactStore) {
+            let contacts = contactStore.get_contacts();
 
-        this._addContactsRecursive(contacts, 0);
+            this._addContactsRecursive(contacts, 0);
+        }
     }
 
     _addContactsRecursive(contacts, index) {
@@ -482,6 +486,12 @@ var Application = GObject.registerClass({
     }
 
     _onWindowDestroy(window) {
+        /* as a workaround, manually dispose the contact store here
+         * to avoid a crash when it's being disposed as a result of the
+         * GC sweep at exit, probably due to some event loop race condition
+         */
+        contactStore.run_dispose();
+        contactStore = null;
         this._mainWindow = null;
     }
 });


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