diff --git a/sys/oneway-malloc/oneway-malloc.c b/sys/oneway-malloc/oneway-malloc.c index fd3d13ca49..3ec46746e7 100644 --- a/sys/oneway-malloc/oneway-malloc.c +++ b/sys/oneway-malloc/oneway-malloc.c @@ -20,15 +20,23 @@ #include +#include "architecture.h" #include "malloc.h" #define ENABLE_DEBUG 0 #include "debug.h" +#define ARCHITECTURE_WORD_MASK (ARCHITECTURE_WORD_BYTES - 1) + extern void *sbrk(int incr); void __attribute__((weak)) *malloc(size_t size) { + /* ensure we always allocate word-aligned blocks */ + if (size & ARCHITECTURE_WORD_MASK) { + size += ARCHITECTURE_WORD_BYTES - (size & ARCHITECTURE_WORD_MASK); + } + if (size != 0) { void *ptr = sbrk(size);