diff options
author | lloyd <[email protected]> | 2012-05-25 21:49:44 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-05-25 21:49:44 +0000 |
commit | 65cc04445f8d40497f02a14bd8cb97081790e54b (patch) | |
tree | 878a161148545cb590febb9026f02dad25769ea5 /src | |
parent | 29c337b2c7024d1b34aa3b578b5fc38b4d869fb0 (diff) |
Two more locking_allocator bugs. In allocate, we did not set
best_fit->first in cases where we had an almost exact match (exact fit
but with some alignment bytes at the start), meaning that not only
would we lose those bytes forever, but that we might later hand out a
range overlapping with what we handed to our current caller.
Also, in deallocate, lower_bound on the freelist might return end()
(for instance if the freelist is entirely empty). Avoid trying to
update the iterator in that case.
Diffstat (limited to 'src')
-rw-r--r-- | src/alloc/locking_allocator/locking_allocator.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/alloc/locking_allocator/locking_allocator.cpp b/src/alloc/locking_allocator/locking_allocator.cpp index 2e9e44c44..cc7d24c8d 100644 --- a/src/alloc/locking_allocator/locking_allocator.cpp +++ b/src/alloc/locking_allocator/locking_allocator.cpp @@ -107,12 +107,16 @@ void* mlock_allocator::allocate(size_t n, size_t alignment) // Need to realign, split the block if(alignment_padding) { + /* + If we used the entire block except for small piece used for + alignment at the beginning, so just update the entry already + in place (as it is in the correct location), rather than + deleting the empty range and inserting the new one in the + same location. + */ if(best_fit->second == 0) { - /* - We used the entire block except for small piece used for - alignment at the beginning, so just update this entry. - */ + best_fit->first = offset; best_fit->second = alignment_padding; } else @@ -145,7 +149,7 @@ bool mlock_allocator::deallocate(void* p, size_t n) std::make_pair(start, 0), comp); // try to merge with later block - if(start + n == i->first) + if(i != m_freelist.end() && start + n == i->first) { i->first = start; i->second += n; |