From a66f8ec04db33e2a5cbc224c03b7ec9865e110c9 Mon Sep 17 00:00:00 2001 From: Aetf Date: Thu, 14 Nov 2019 16:06:10 -0500 Subject: [PATCH] FdoSecrets: fix crash when enabling the plugin on a non-exposed database --- src/fdosecrets/objects/Collection.h | 5 +++++ src/fdosecrets/objects/Service.cpp | 26 +++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/fdosecrets/objects/Collection.h b/src/fdosecrets/objects/Collection.h index de9db3a49..902860165 100644 --- a/src/fdosecrets/objects/Collection.h +++ b/src/fdosecrets/objects/Collection.h @@ -74,6 +74,10 @@ namespace FdoSecrets public: DBusReturn setProperties(const QVariantMap& properties); + bool isValid() const { + return backend(); + } + DBusReturn removeAlias(QString alias); DBusReturn addAlias(QString alias); const QSet aliases() const; @@ -106,6 +110,7 @@ namespace FdoSecrets private slots: void onDatabaseLockChanged(); void onDatabaseExposedGroupChanged(); + // force reload info from backend, potentially delete self void reloadBackend(); private: diff --git a/src/fdosecrets/objects/Service.cpp b/src/fdosecrets/objects/Service.cpp index 6bca1f12c..eeded79ba 100644 --- a/src/fdosecrets/objects/Service.cpp +++ b/src/fdosecrets/objects/Service.cpp @@ -93,7 +93,24 @@ namespace FdoSecrets void Service::onDatabaseTabOpened(DatabaseWidget* dbWidget, bool emitSignal) { + // The Collection will monitor the database's exposed group. + // When the Collection finds that no exposed group, it will delete itself. + // Thus the service also needs to monitor it and recreate the collection if the user changes + // from no exposed to exposed something. + if (!dbWidget->isLocked()) { + monitorDatabaseExposedGroup(dbWidget); + } + connect(dbWidget, &DatabaseWidget::databaseUnlocked, this, [this, dbWidget]() { + monitorDatabaseExposedGroup(dbWidget); + }); + auto coll = new Collection(this, dbWidget); + // Creation may fail if the database is not exposed. + // This is okay, because we monitor the expose settings above + if (!coll->isValid()) { + coll->deleteLater(); + return; + } m_collections << coll; m_dbToCollection[dbWidget] = coll; @@ -127,15 +144,6 @@ namespace FdoSecrets emit collectionDeleted(coll); }); - // a special case: the database changed from no expose to expose something. - // in this case, there is no collection out there monitoring it, so create a new collection - if (!dbWidget->isLocked()) { - monitorDatabaseExposedGroup(dbWidget); - } - connect(dbWidget, &DatabaseWidget::databaseUnlocked, this, [this, dbWidget]() { - monitorDatabaseExposedGroup(dbWidget); - }); - if (emitSignal) { emit collectionCreated(coll); }