1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 19:31:02 +01:00

Don't crash on exit when unregistering cover providers

This commit is contained in:
David Sansome 2011-06-22 19:06:57 +00:00
parent 6e86caae2c
commit 2e9ec3e9d4
2 changed files with 15 additions and 5 deletions

View File

@ -27,7 +27,7 @@ CoverProviders::CoverProviders()
void CoverProviders::AddProvider(CoverProvider* provider) {
{
QMutexLocker locker(&mutex_);
cover_providers_.append(provider);
cover_providers_.insert(provider, provider->name());
}
qLog(Debug) << "Registered cover provider" << provider->name();
@ -39,11 +39,20 @@ void CoverProviders::RemoveProvider(CoverProvider* provider) {
if (!provider)
return;
qLog(Debug) << "Unregistered cover provider" << provider->name();
// It's not safe to dereference provider at this pointbecause it might have
// already been destroyed.
QString name;
{
QMutexLocker locker(&mutex_);
cover_providers_.removeAll(provider);
name = cover_providers_.take(provider);
}
if (name.isNull()) {
qLog(Debug) << "Tried to remove a cover provider that was not registered";
} else {
qLog(Debug) << "Unregistered cover provider" << name;
}
}

View File

@ -18,6 +18,7 @@
#ifndef COVERPROVIDERS_H
#define COVERPROVIDERS_H
#include <QMap>
#include <QMutex>
#include <QObject>
@ -44,7 +45,7 @@ public:
void RemoveProvider(CoverProvider* provider);
// Returns a list of cover providers
QList<CoverProvider*> List() const { return cover_providers_; }
QList<CoverProvider*> List() const { return cover_providers_.keys(); }
// Returns true if this repository has at least one registered provider.
bool HasAnyProviders() const { return !cover_providers_.isEmpty(); }
@ -58,7 +59,7 @@ private:
~CoverProviders() {}
Q_DISABLE_COPY(CoverProviders);
QList<CoverProvider*> cover_providers_;
QMap<CoverProvider*, QString> cover_providers_;
QMutex mutex_;
QAtomicInt next_id_;