Skip to content

Commit

Permalink
Fix memory leak when not using guard pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Pansysk75 committed Jul 28, 2023
1 parent bdfd6d4 commit 34c0636
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,21 @@ namespace hpx::threads::coroutines::detail::posix {

inline void* alloc_stack(std::size_t size)
{
void* real_stack =
::mmap(nullptr, size + EXEC_PAGESIZE, PROT_READ | PROT_WRITE,
#if defined(HPX_HAVE_THREAD_GUARD_PAGE)
if (use_guard_pages)
{
size += EXEC_PAGESIZE;
}
#endif
void* real_stack = ::mmap(nullptr, size, PROT_READ | PROT_WRITE,
#if defined(__APPLE__)
MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
#elif defined(__FreeBSD__)
MAP_PRIVATE | MAP_ANON,
MAP_PRIVATE | MAP_ANON,
#else
MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
#endif
-1, 0);
-1, 0);

if (real_stack == MAP_FAILED)
{
Expand All @@ -112,7 +117,7 @@ namespace hpx::threads::coroutines::detail::posix {
#if defined(HPX_HAVE_THREAD_GUARD_PAGE)
if (use_guard_pages)
{
// Add a guard page.
// Set the guard page.
::mprotect(real_stack, EXEC_PAGESIZE, PROT_NONE);

void** stack = static_cast<void**>(real_stack) +
Expand Down

0 comments on commit 34c0636

Please sign in to comment.