1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-28836 fixup

On GNU/Linux, even though the C11 aligned_alloc() appeared in
GNU libc early on, some custom memory allocators did not
implement it until recently. For example, before
gperftools/gperftools@d406f22853
the free() in tcmalloc would fail to free memory that was
returned by aligned_alloc(), because the latter would map to the
built-in allocator of libc. The Linux specific memalign() has a
similar interface and is safer to use, because it has been
available for a longer time. For AddressSanitizer, we will use
aligned_alloc() so that the constraint on size can be enforced.

buf_tmp_reserve_compression_buf(): When HAVE_ALIGNED_ALLOC holds,
round up the size to be an integer multiple of the alignment.

pfs_malloc(): In the unit test stub, round up the size to be an
integer multiple of the alignment.
This commit is contained in:
Marko Mäkelä
2022-06-22 08:23:32 +03:00
parent 3794673111
commit 0fa19fdebf
4 changed files with 22 additions and 3 deletions

View File

@@ -14,12 +14,19 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
#ifdef HAVE_ALIGNED_ALLOC
#elif defined __linux__
# include <malloc.h>
#endif
inline void *aligned_malloc(size_t size, size_t alignment)
{
#ifdef _WIN32
return _aligned_malloc(size, alignment);
#elif defined HAVE_ALIGNED_ALLOC
return aligned_alloc(alignment, size);
#elif defined __linux__
return memalign(alignment, size);
#else
void *result;
if (posix_memalign(&result, alignment, size))