From 6f8cb38591a8a721c45cafffde3430f549ba176e Mon Sep 17 00:00:00 2001 From: Phil Carmody Date: Mon, 28 Jul 2014 16:45:33 +0300 Subject: [PATCH] lib: data-stack - fix incorrect pointer comparison in t_try_realloc in DEBUG builds When trying to work out if it's a valid realloc, we need to remember that in DEBUG builds, we have hidden a size value (in a MEM_ALIGNED space) before the pointer we return. Signed-off-by: Phil Carmody --- src/lib/data-stack.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/data-stack.c b/src/lib/data-stack.c index 5da7a8ae00..e197f3772c 100644 --- a/src/lib/data-stack.c +++ b/src/lib/data-stack.c @@ -454,7 +454,7 @@ void *t_malloc0(size_t size) bool t_try_realloc(void *mem, size_t size) { - size_t last_alloc_size; + size_t debug_adjust = 0, last_alloc_size; unsigned char *after_last_alloc; if (unlikely(size == 0 || size > SSIZE_T_MAX)) @@ -465,7 +465,10 @@ bool t_try_realloc(void *mem, size_t size) /* see if we're trying to grow the memory we allocated last */ after_last_alloc = data_stack_after_last_alloc(current_block); - if (after_last_alloc - last_alloc_size == mem) { +#ifdef DEBUG + debug_adjust = MEM_ALIGN(sizeof(size_t)); +#endif + if (after_last_alloc - last_alloc_size + debug_adjust == mem) { /* yeah, see if we have space to grow */ size_t new_alloc_size, alloc_growth; -- 2.47.3