mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 23:04:29 +00:00
Fix dangling pointers to a reallocated vector when there are multiple source versions for handover
This commit is contained in:
parent
ef632804ef
commit
a0b16305c9
@ -331,8 +331,6 @@ void RealmCoordinator::run_async_notifiers()
|
||||
change_info.resize(1);
|
||||
}
|
||||
else {
|
||||
change_info.resize(2);
|
||||
|
||||
// Sort newly added notifiers by their source version so that we can pull them
|
||||
// all forward to the latest version in a single pass over the transaction log
|
||||
std::sort(new_notifiers.begin(), new_notifiers.end(),
|
||||
@ -340,6 +338,18 @@ void RealmCoordinator::run_async_notifiers()
|
||||
version = m_advancer_sg->get_version_of_current_transaction();
|
||||
REALM_ASSERT(version == new_notifiers.front()->version());
|
||||
|
||||
// Preallocate the required amount of space in the vector so that we can
|
||||
// safely give out pointers to within the vector
|
||||
{
|
||||
size_t count = 2;
|
||||
for (auto it = new_notifiers.begin(), next = it + 1; next != new_notifiers.end(); ++it, ++next) {
|
||||
if ((*it)->version() != (*next)->version())
|
||||
++count;
|
||||
}
|
||||
change_info.reserve(count);
|
||||
change_info.resize(2);
|
||||
}
|
||||
|
||||
TransactionChangeInfo* info = &change_info.back();
|
||||
|
||||
// Advance each of the new notifiers to the latest version, attaching them
|
||||
|
Loading…
x
Reference in New Issue
Block a user