From d95aeb450fec9c4e4836179f7cdf6fcafba3e119 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 14 Jul 2018 05:34:32 +0000 Subject: internal_memalign: do not assume real_malloc succeeds Oops :x --- ext/mwrap/mwrap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c index c0cf8ff..fa52631 100644 --- a/ext/mwrap/mwrap.c +++ b/ext/mwrap/mwrap.c @@ -408,12 +408,14 @@ static void *internal_memalign(size_t alignment, size_t size, uintptr_t caller) /* assert(asize == (alignment + size + sizeof(struct alloc_hdr))); */ rcu_read_lock(); l = update_stats_rcu(size, caller); - real = real_malloc(asize); - p = hdr2ptr(real); - if (!ptr_is_aligned(p, alignment)) - p = ptr_align(p, alignment); - h = ptr2hdr(p); - alloc_insert_rcu(l, h, size, real); + p = real = real_malloc(asize); + if (real) { + p = hdr2ptr(real); + if (!ptr_is_aligned(p, alignment)) + p = ptr_align(p, alignment); + h = ptr2hdr(p); + alloc_insert_rcu(l, h, size, real); + } rcu_read_unlock(); return p; -- cgit v1.2.3-24-ge0c7