Skip to content

Commit 3d3d8f1

Browse files
committed
MDEV-21337 fix aligned_malloc()
do not fallback to malloc(), always return properly aligned buffer
1 parent 984b3c1 commit 3d3d8f1

File tree

4 files changed

+10
-26
lines changed

4 files changed

+10
-26
lines changed

storage/innobase/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ IF(NOT MSVC)
9494
SET_SOURCE_FILES_PROPERTIES(trx/trx0rec.cc PROPERTIES COMPILE_FLAGS -O1)
9595
ENDIF()
9696

97-
CHECK_FUNCTION_EXISTS(posix_memalign HAVE_POSIX_MEMALIGN)
98-
IF(HAVE_POSIX_MEMALIGN)
99-
ADD_DEFINITIONS(-DHAVE_POSIX_MEMALIGN)
100-
ENDIF()
101-
10297
# either define HAVE_IB_GCC_ATOMIC_BUILTINS or not
10398
# workaround for old gcc on x86, gcc atomic ops only work under -march=i686
10499
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND CMAKE_COMPILER_IS_GNUCC AND

storage/innobase/buf/buf0buf.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,16 @@ Created 11/5/1995 Heikki Tuuri
8282
#include "snappy-c.h"
8383
#endif
8484

85-
inline void* aligned_malloc(size_t size, size_t align) {
86-
void *result;
85+
static void *aligned_malloc(size_t size, size_t align)
86+
{
8787
#ifdef _MSC_VER
88-
result = _aligned_malloc(size, align);
89-
#elif defined (HAVE_POSIX_MEMALIGN)
90-
if(posix_memalign(&result, align, size)) {
91-
result = 0;
92-
}
88+
return _aligned_malloc(size, align);
9389
#else
94-
/* Use unaligned malloc as fallback */
95-
result = malloc(size);
90+
void *result;
91+
if (posix_memalign(&result, align, size))
92+
result= NULL;
9693
#endif
97-
return result;
94+
return result;
9895
}
9996

10097
inline void aligned_free(void *ptr) {

storage/xtradb/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-class-memaccess")
9393

9494
IF(NOT MSVC)
9595

96-
CHECK_FUNCTION_EXISTS(posix_memalign HAVE_POSIX_MEMALIGN)
97-
IF(HAVE_POSIX_MEMALIGN)
98-
ADD_DEFINITIONS(-DHAVE_POSIX_MEMALIGN)
99-
ENDIF()
100-
10196
# either define HAVE_IB_GCC_ATOMIC_BUILTINS or not
10297
# workaround for old gcc on x86, gcc atomic ops only work under -march=i686
10398
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND CMAKE_COMPILER_IS_GNUCC AND

storage/xtradb/buf/buf0buf.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,14 @@ buf_mark_space_corrupt(
9292
/* prototypes for new functions added to ha_innodb.cc */
9393
trx_t* innobase_get_trx();
9494

95-
inline void* aligned_malloc(size_t size, size_t align) {
95+
static void* aligned_malloc(size_t size, size_t align) {
9696
void *result;
9797
#ifdef _MSC_VER
9898
result = _aligned_malloc(size, align);
99-
#elif defined (HAVE_POSIX_MEMALIGN)
99+
#else
100100
if(posix_memalign(&result, align, size)) {
101-
result = 0;
101+
result = NULL;
102102
}
103-
#else
104-
/* Use unaligned malloc as fallback */
105-
result = malloc(size);
106103
#endif
107104
return result;
108105
}

0 commit comments

Comments
 (0)