Move assert() calls up in arena_run_reg_alloc().

Move assert() calls up in arena_run_reg_alloc(), so that a corrupt
pointer will likely be caught by an assertion *before* it is
dereferenced.
This commit is contained in:
Jason Evans 2010-08-05 12:13:42 -07:00
parent 2541e1b083
commit dcd15098a8

View File

@ -254,7 +254,6 @@ arena_run_reg_alloc(arena_run_t *run, arena_bin_t *bin)
run->nfree--; run->nfree--;
ret = run->avail; ret = run->avail;
if (ret != NULL) { if (ret != NULL) {
run->avail = *(void **)ret;
/* Double free can cause assertion failure.*/ /* Double free can cause assertion failure.*/
assert(ret != NULL); assert(ret != NULL);
/* Write-after free can cause assertion failure. */ /* Write-after free can cause assertion failure. */
@ -264,6 +263,7 @@ arena_run_reg_alloc(arena_run_t *run, arena_bin_t *bin)
assert(((uintptr_t)ret - ((uintptr_t)run + assert(((uintptr_t)ret - ((uintptr_t)run +
(uintptr_t)bin->reg0_offset)) % (uintptr_t)bin->reg_size == (uintptr_t)bin->reg0_offset)) % (uintptr_t)bin->reg_size ==
0); 0);
run->avail = *(void **)ret;
return (ret); return (ret);
} }
ret = run->next; ret = run->next;