Skip to content

Commit

Permalink
FdoSecrets: fix crash when enabling the plugin on a non-exposed database
Browse files Browse the repository at this point in the history
  • Loading branch information
Aetf authored and droidmonkey committed Nov 23, 2019
1 parent e2c95f7 commit a66f8ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/fdosecrets/objects/Collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ namespace FdoSecrets
public:
DBusReturn<void> setProperties(const QVariantMap& properties);

bool isValid() const {
return backend();
}

DBusReturn<void> removeAlias(QString alias);
DBusReturn<void> addAlias(QString alias);
const QSet<QString> aliases() const;
Expand Down Expand Up @@ -106,6 +110,7 @@ namespace FdoSecrets
private slots:
void onDatabaseLockChanged();
void onDatabaseExposedGroupChanged();
// force reload info from backend, potentially delete self
void reloadBackend();

private:
Expand Down
26 changes: 17 additions & 9 deletions src/fdosecrets/objects/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit a66f8ec

Please sign in to comment.