Skip to content

Commit

Permalink
LockedPool: fix explosion for illegal-sized alloc
Browse files Browse the repository at this point in the history
Check for unreasonable alloc size in LockedPool rather than lancing through new
Arenas until we improbably find one worthy of the quixotic request or the system
can support no more Arenas.
  • Loading branch information
kazcw committed Nov 2, 2016
1 parent 21b8f3d commit 0b59f80
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/support/lockedpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ LockedPool::~LockedPool()
void* LockedPool::alloc(size_t size)
{
std::lock_guard<std::mutex> lock(mutex);

// Don't handle impossible sizes
if (size == 0 || size > ARENA_SIZE)
return nullptr;

// Try allocating from each current arena
for (auto &arena: arenas) {
void *addr = arena.alloc(size);
Expand Down

0 comments on commit 0b59f80

Please sign in to comment.