Skip to content

Commit

Permalink
Fix breakage from PR #1869 due to using Qt 5 features not supported o…
Browse files Browse the repository at this point in the history
…n Trusty/Xenial.

Also fixes a potential race condition in MusicBrainzClient/AcoustidClient where
m_requests temporarily contains deleted pointers.
  • Loading branch information
rryan committed Oct 28, 2018
1 parent 3da63b2 commit db7fe92
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/control/controlobjectscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void ControlObjectScript::removeScriptConnection(const ScriptConnection& conn) {

void ControlObjectScript::disconnectAllConnectionsToFunction(const QScriptValue& function) {
// Make a local copy of m_scriptConnections because items are removed within the loop.
const QVector<ScriptConnection> connections = m_scriptConnections;
const QList<ScriptConnection> connections = m_scriptConnections;
for (const auto& conn: connections) {
if (conn.callback.strictlyEquals(function)) {
removeScriptConnection(conn);
Expand All @@ -70,7 +70,7 @@ void ControlObjectScript::slotValueChanged(double value, QObject*) {
// This allows a script to disconnect a callback from inside the
// the callback. Otherwise the this may crash since the disconnect call
// happens during conn.function.call() in the middle of the loop below.
const QVector<ScriptConnection> connections = m_scriptConnections;
const QList<ScriptConnection> connections = m_scriptConnections;
for (auto&& conn: connections) {
conn.executeCallback(value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/control/controlobjectscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ControlObjectScript : public ControlProxy {
void slotValueChanged(double v, QObject*);

private:
QVector<ScriptConnection> m_scriptConnections;
QList<ScriptConnection> m_scriptConnections;
};

#endif // CONTROLOBJECTSCRIPT_H
7 changes: 6 additions & 1 deletion src/musicbrainz/acoustidclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ void AcoustidClient::cancel(int id) {
}

void AcoustidClient::cancelAll() {
qDeleteAll(m_requests.keyBegin(), m_requests.keyEnd());
auto requests = m_requests;
m_requests.clear();

for (auto it = requests.constBegin();
it != requests.constEnd(); ++it) {
delete it.key();
}
}

void AcoustidClient::requestFinished() {
Expand Down
6 changes: 5 additions & 1 deletion src/musicbrainz/musicbrainzclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ void MusicBrainzClient::cancel(int id) {
}

void MusicBrainzClient::cancelAll() {
qDeleteAll(m_requests.keyBegin(), m_requests.keyEnd());
auto requests = m_requests;
m_requests.clear();
for (auto it = requests.constBegin();
it != requests.constEnd(); ++it) {
delete it.key();
}
}

namespace {
Expand Down

0 comments on commit db7fe92

Please sign in to comment.