summaryrefslogtreecommitdiff
path: root/malloc/hooks.c
diff options
context:
space:
mode:
authorOndřej Bílka <neleai@seznam.cz>2013-11-20 15:46:02 +0100
committerOndřej Bílka <neleai@seznam.cz>2013-11-20 15:46:02 +0100
commit10ad46bc6526edc5c7afcc57112da96917ff3629 (patch)
tree9bd94011a94320e7d8b4391be57cda1b1026a2b4 /malloc/hooks.c
parent4712799fbb6812cc73f7bd9c8faa6e7b05c0f5ab (diff)
downloadglibc-10ad46bc6526edc5c7afcc57112da96917ff3629.tar.gz
Consolidate valloc/pvalloc code.
To make malloc code more maintainable we make malloc and pvalloc share logic with memalign.
Diffstat (limited to 'malloc/hooks.c')
-rw-r--r--malloc/hooks.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/malloc/hooks.c b/malloc/hooks.c
index 1dbe93f383..89fbd3c948 100644
--- a/malloc/hooks.c
+++ b/malloc/hooks.c
@@ -376,6 +376,13 @@ memalign_check(size_t alignment, size_t bytes, const void *caller)
return 0;
}
+ /* Make sure alignment is power of 2. */
+ if (!powerof2(alignment)) {
+ size_t a = MALLOC_ALIGNMENT * 2;
+ while (a < alignment) a <<= 1;
+ alignment = a;
+ }
+
(void)mutex_lock(&main_arena.mutex);
mem = (top_check() >= 0) ? _int_memalign(&main_arena, alignment, bytes+1) :
NULL;