Skip to content

Commit

Permalink
Fix potential data race
Browse files Browse the repository at this point in the history
This case could be considered benign however it could still be an
undefined behavior to the compiler, so remove it.

Ref:
https://hacks.mozilla.org/2021/04/eliminating-data-races-in-firefox-a-technical-report/
  • Loading branch information
Chocobo1 committed May 7, 2021
1 parent 05e3e46 commit a82ca6a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/base/settingsstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,8 @@ SettingsStorage *SettingsStorage::instance()

bool SettingsStorage::save()
{
if (!m_dirty) return true; // Obtaining the lock is expensive, let's check early
const QWriteLocker locker(&m_lock); // to guard for `m_dirty`
if (!m_dirty) return true; // something might have changed while we were getting the lock
const QWriteLocker locker(&m_lock); // guard for `m_dirty` too
if (!m_dirty) return true;

const TransactionalSettings settings(QLatin1String("qBittorrent"));
if (!settings.write(m_data))
Expand Down

0 comments on commit a82ca6a

Please sign in to comment.