mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-16 02:42:23 +08:00
Fixed a memory bug.
While replacing std::map with std::deque. Don't store any pointers because emplace can invalidate iterators.
This commit is contained in:
parent
0ac313500d
commit
7a58b17e4e
@ -538,11 +538,13 @@ public:
|
|||||||
|
|
||||||
Future<Void> forgetVersionsBeforeAsync( Version newOldestVersion, TaskPriority taskID = TaskPriority::DefaultYield ) {
|
Future<Void> forgetVersionsBeforeAsync( Version newOldestVersion, TaskPriority taskID = TaskPriority::DefaultYield ) {
|
||||||
ASSERT( newOldestVersion <= latestVersion );
|
ASSERT( newOldestVersion <= latestVersion );
|
||||||
// since the specified newOldestVersion might not exist, we copy the root from next lower version to newOldestVersion position
|
|
||||||
//roots[newOldestVersion] = getRoot(newOldestVersion);
|
//roots[newOldestVersion] = getRoot(newOldestVersion);
|
||||||
auto r = upper_bound(roots.begin(), roots.end(), newOldestVersion, compare());
|
// if the specified newOldestVersion does not exist, copy the root from next lower version to newOldestVersion position
|
||||||
r--;
|
if (!binary_search(roots.begin(), roots.end(), newOldestVersion, compare())) {
|
||||||
roots.insert(upper_bound(roots.begin(), roots.end(), newOldestVersion, compare()), *r);
|
//auto r = upper_bound(roots.begin(), roots.end(), newOldestVersion, compare());
|
||||||
|
//r--;
|
||||||
|
roots.emplace(upper_bound(roots.begin(), roots.end(), newOldestVersion, compare()), newOldestVersion, getRoot(newOldestVersion));
|
||||||
|
}
|
||||||
|
|
||||||
vector<Tree> toFree;
|
vector<Tree> toFree;
|
||||||
toFree.reserve(10000);
|
toFree.reserve(10000);
|
||||||
@ -572,7 +574,7 @@ public:
|
|||||||
latestVersion = version;
|
latestVersion = version;
|
||||||
Tree r = getRoot(version);
|
Tree r = getRoot(version);
|
||||||
//latestRoot = &roots[version];
|
//latestRoot = &roots[version];
|
||||||
roots.emplace_back(version, Tree());
|
roots.emplace_back(version, r);
|
||||||
//latestRoot = &(roots.emplace_back(version, Tree()).second);
|
//latestRoot = &(roots.emplace_back(version, Tree()).second);
|
||||||
//*latestRoot = r;
|
//*latestRoot = r;
|
||||||
} else ASSERT( version == latestVersion );
|
} else ASSERT( version == latestVersion );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user