diff --git a/src/support/allocators/secure.h b/src/support/allocators/secure.h --- a/src/support/allocators/secure.h +++ b/src/support/allocators/secure.h @@ -35,8 +35,12 @@ }; T *allocate(std::size_t n, const void *hint = 0) { - return static_cast( + T *allocation = static_cast( LockedPoolManager::Instance().alloc(sizeof(T) * n)); + if (!allocation) { + throw std::bad_alloc(); + } + return allocation; } void deallocate(T *p, std::size_t n) { diff --git a/src/support/lockedpool.h b/src/support/lockedpool.h --- a/src/support/lockedpool.h +++ b/src/support/lockedpool.h @@ -22,7 +22,7 @@ /** * Allocate and lock memory pages. * If len is not a multiple of the system page size, it is rounded up. - * Returns 0 in case of allocation failure. + * Returns nullptr in case of allocation failure. * * If locking the memory pages could not be accomplished it will still * return the memory, however the lockingSuccess flag will be false. diff --git a/src/support/lockedpool.cpp b/src/support/lockedpool.cpp --- a/src/support/lockedpool.cpp +++ b/src/support/lockedpool.cpp @@ -250,6 +250,9 @@ len = align_up(len, page_size); addr = mmap(nullptr, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (addr == MAP_FAILED) { + return nullptr; + } if (addr) { *lockingSuccess = mlock(addr, len) == 0; }