Skip to content

Commit

Permalink
my_large_pages: remove conventional memory(my_malloc_lock) fallback
Browse files Browse the repository at this point in the history
Both Windows and MMAP capable implementations fell back to a
non-MEM_LARGE_PAGES/HugeTLB allocation with the large page implementaion
failed. These can can be freed by the corresponding function.

Prior to this, if we fell back to a conventional memory, than will
results in deallocation using munmap/VirtualFree on a memory allocated
using my_malloc_lock. At worst this could succeed and the
my_malloc_lock looses its memory without knowing about it.
  • Loading branch information
grooverdan authored and svoj committed Apr 8, 2020
1 parent ccc0693 commit 7b7a916
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions mysys/my_largepage.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,21 +380,14 @@ uchar* my_large_malloc(size_t *size, myf my_flags)
break; /* no more options to try */
}
}
#else
DBUG_RETURN(my_malloc_lock(*size, my_flags));
#endif /* defined(HAVE_MMAP) */

if (ptr != NULL)
{
MEM_MAKE_DEFINED(ptr, *size);
DBUG_RETURN(ptr);
}
ptr= my_malloc_lock(*size, my_flags);

#ifdef HAVE_LARGE_PAGES
if (my_flags & MY_WME)
fprintf(stderr,
"Warning: Using conventional memory pool to allocate %p, size %zu\n",
ptr, *size);
#endif

DBUG_RETURN(ptr);
}
Expand Down Expand Up @@ -424,22 +417,13 @@ void my_large_free(void *ptr, size_t size)
#if defined(HAVE_MMAP) && !defined(_WIN32)
if (munmap(ptr, size))
{
/*
This occurs when the original allocation fell back to conventional
memory so ignore the EINVAL error.
*/
if (errno != EINVAL)
{
fprintf(stderr,
"Warning: Failed to unmap location %p, %zu bytes, errno %d\n",
ptr, size, errno);
DBUG_VOID_RETURN;
}
fprintf(stderr,
"Warning: Failed to unmap location %p, %zu bytes, errno %d\n",
ptr, size, errno);
}
else
{
MEM_UNDEFINED(ptr, size);
DBUG_VOID_RETURN;
}
#elif defined(_WIN32)
/*
Expand All @@ -454,10 +438,10 @@ void my_large_free(void *ptr, size_t size)
else
{
MEM_UNDEFINED(ptr, size);
DBUG_VOID_RETURN;
}
#endif
#else
my_free_lock(ptr);
#endif

DBUG_VOID_RETURN;
}

0 comments on commit 7b7a916

Please sign in to comment.