Skip to content

Commit

Permalink
Merge pull request musescore#26404 from cbjeukendrup/crash_export_aud…
Browse files Browse the repository at this point in the history
…io_asyncimpl_25884

Fix crash because of data race in `AsyncImpl::onCall`
  • Loading branch information
DmitryArefiev authored Feb 10, 2025
2 parents b4cee3f + 447baec commit ce0104b
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,13 @@ AsyncImpl* AsyncImpl::instance()
void AsyncImpl::disconnectAsync(Asyncable* caller)
{
std::lock_guard locker(m_mutex);
uint64_t key = 0;
std::map<uint64_t, Call>::const_iterator it = m_calls.cbegin(), end = m_calls.cend();
for (; it != end; ++it) {

for (auto it = m_calls.cbegin(), end = m_calls.cend(); it != end; ++it) {
if (it->second.caller == caller) {
key = it->first;
m_calls.erase(it);
break;
}
}

if (key) {
m_calls.erase(key);
}
}

void AsyncImpl::call(Asyncable* caller, IFunction* f, const std::thread::id& th)
Expand Down Expand Up @@ -79,14 +74,15 @@ void AsyncImpl::onCall(uint64_t key)
}

c = it->second;

m_calls.erase(it);

if (c.caller) {
c.caller->disconnectAsync(this);
}
}

c.f->call();

if (c.caller) {
c.caller->disconnectAsync(this);
}

delete c.f;
}

0 comments on commit ce0104b

Please sign in to comment.