From ab071c304d74d464b47feb83f1353d6dfe5e1b1f Mon Sep 17 00:00:00 2001 From: jasone Date: Tue, 10 Jun 2008 15:46:18 +0000 Subject: In the error path through base_alloc(), release base_mtx [1]. Fix bit vector initialization for run headers. Submitted by: [1] Mike Schuster --- lib/libc/stdlib/malloc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 01160f4..629d343 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -1296,8 +1296,10 @@ base_alloc(size_t size) malloc_mutex_lock(&base_mtx); /* Make sure there's enough space for the allocation. */ if ((uintptr_t)base_next_addr + csize > (uintptr_t)base_past_addr) { - if (base_pages_alloc(csize)) + if (base_pages_alloc(csize)) { + malloc_mutex_unlock(&base_mtx); return (NULL); + } } /* Allocate. */ ret = base_next_addr; @@ -2684,10 +2686,12 @@ arena_bin_nonfull_run_get(arena_t *arena, arena_bin_t *bin) /* Initialize run internals. */ run->bin = bin; - for (i = 0; i < bin->regs_mask_nelms; i++) + for (i = 0; i < bin->regs_mask_nelms - 1; i++) run->regs_mask[i] = UINT_MAX; remainder = bin->nregs & ((1U << (SIZEOF_INT_2POW + 3)) - 1); - if (remainder != 0) { + if (remainder == 0) + run->regs_mask[i] = UINT_MAX; + else { /* The last element has spare bits that need to be unset. */ run->regs_mask[i] = (UINT_MAX >> ((1U << (SIZEOF_INT_2POW + 3)) - remainder)); -- cgit v1.1