Skip to content

Commit

Permalink
Fix QMap usage where insertion on read of missing value was not intended
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Dec 26, 2018
1 parent 82230ef commit c5d70c4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/backend/computermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void ComputerManager::saveHosts()
settings.beginWriteArray(SER_HOSTS);
for (int i = 0; i < m_KnownHosts.count(); i++) {
settings.setArrayIndex(i);
m_KnownHosts[m_KnownHosts.keys()[i]]->serialize(settings);
m_KnownHosts.value(m_KnownHosts.keys()[i])->serialize(settings);
}
settings.endArray();
}
Expand Down Expand Up @@ -266,7 +266,7 @@ void ComputerManager::startPollingComputer(NvComputer* computer)
}

if (m_PollThreads.contains(computer->uuid)) {
Q_ASSERT(m_PollThreads[computer->uuid]->isRunning());
Q_ASSERT(m_PollThreads.value(computer->uuid)->isRunning());
return;
}

Expand Down Expand Up @@ -324,9 +324,8 @@ class DeferredHostDeletionTask : public QRunnable
{
QWriteLocker lock(&m_ComputerManager->m_Lock);

pollingThread = m_ComputerManager->m_PollThreads[m_Computer->uuid];
pollingThread = m_ComputerManager->m_PollThreads.take(m_Computer->uuid);

m_ComputerManager->m_PollThreads.remove(m_Computer->uuid);
m_ComputerManager->m_KnownHosts.remove(m_Computer->uuid);
}

Expand Down Expand Up @@ -588,7 +587,7 @@ class PendingAddTask : public QObject, public QRunnable
NvComputer* existingComputer;
{
QReadLocker lock(&m_ComputerManager->m_Lock);
existingComputer = m_ComputerManager->m_KnownHosts[newComputer->uuid];
existingComputer = m_ComputerManager->m_KnownHosts.value(newComputer->uuid);
if (existingComputer != nullptr) {
http.setServerCert(existingComputer->serverCert);
}
Expand Down Expand Up @@ -627,7 +626,7 @@ class PendingAddTask : public QObject, public QRunnable
{
// Check if this PC already exists
QWriteLocker lock(&m_ComputerManager->m_Lock);
NvComputer* existingComputer = m_ComputerManager->m_KnownHosts[newComputer->uuid];
NvComputer* existingComputer = m_ComputerManager->m_KnownHosts.value(newComputer->uuid);
if (existingComputer != nullptr) {
// Fold it into the existing PC
bool changed = existingComputer->update(*newComputer);
Expand Down

0 comments on commit c5d70c4

Please sign in to comment.