Add alignment assertions to public aligned allocation functions.

This commit is contained in:
Jason Evans 2015-06-22 18:48:58 -07:00
parent 4f6f2b131e
commit dc0610a714

View File

@ -1472,7 +1472,7 @@ imemalign(void **memptr, size_t alignment, size_t size, size_t min_alignment)
if (unlikely(malloc_init())) {
result = NULL;
goto label_oom;
} else {
}
tsd = tsd_fetch();
if (size == 0)
size = 1;
@ -1502,7 +1502,7 @@ imemalign(void **memptr, size_t alignment, size_t size, size_t min_alignment)
result = ipalloc(tsd, usize, alignment, false);
if (unlikely(result == NULL))
goto label_oom;
}
assert(((uintptr_t)result & (alignment - 1)) == ZU(0));
*memptr = result;
ret = 0;
@ -1986,12 +1986,14 @@ imallocx_prof(tsd_t *tsd, size_t size, int flags, size_t *usize)
}
prof_malloc(p, *usize, tctx);
assert(alignment == 0 || ((uintptr_t)p & (alignment - 1)) == ZU(0));
return (p);
}
JEMALLOC_ALWAYS_INLINE_C void *
imallocx_no_prof(tsd_t *tsd, size_t size, int flags, size_t *usize)
{
void *p;
size_t alignment;
bool zero;
tcache_t *tcache;
@ -2006,7 +2008,9 @@ imallocx_no_prof(tsd_t *tsd, size_t size, int flags, size_t *usize)
if (unlikely(imallocx_flags_decode_hard(tsd, size, flags, usize,
&alignment, &zero, &tcache, &arena)))
return (NULL);
return (imallocx_flags(tsd, *usize, alignment, zero, tcache, arena));
p = imallocx_flags(tsd, *usize, alignment, zero, tcache, arena);
assert(alignment == 0 || ((uintptr_t)p & (alignment - 1)) == ZU(0));
return (p);
}
void *
@ -2160,6 +2164,7 @@ je_rallocx(void *ptr, size_t size, int flags)
if (config_stats || (config_valgrind && unlikely(in_valgrind)))
usize = isalloc(p, config_prof);
}
assert(alignment == 0 || ((uintptr_t)p & (alignment - 1)) == ZU(0));
if (config_stats) {
*tsd_thread_allocatedp_get(tsd) += usize;