diff options
-rw-r--r-- | libheap/malloc.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libheap/malloc.c b/libheap/malloc.c index 9a4a07e..676f754 100644 --- a/libheap/malloc.c +++ b/libheap/malloc.c @@ -25,6 +25,9 @@ #endif #endif +#if CONFIG_HEAP_VALGRIND + #include <valgrind/valgrind.h> +#endif #if CONFIG_COROUTINE_VALGRIND #include <valgrind/memcheck.h> #endif @@ -176,6 +179,8 @@ static bool heap_alloc_can_alloc(struct waiter *waiter, bool check [[maybe_unuse return false; } +#define REDZONE 0 + void *__lm_heap_aligned_realloc(void *ptr, size_t align, size_t size) { heap_ensure_init(); @@ -308,6 +313,13 @@ void *__lm_heap_aligned_realloc(void *ptr, size_t align, size_t size) { if (mode == MODE_SIMPLE && ptr) __lm_heap_free(ptr); +#if CONFIG_HEAP_VALGRIND + if (old_rec && choice == old_rec) + VALGRIND_RESIZEINPLACE_BLOCK(ret, old_size, heap_record_size(choice), REDZONE); + else + VALGRIND_MALLOCLIKE_BLOCK(ret, heap_record_size(choice), REDZONE, true); +#endif + /* return ====================*/ if (heap_meta.waiters.front && heap_alloc_can_alloc(&heap_meta.waiters.front->val, false)) @@ -349,6 +361,10 @@ void __lm_heap_free(void *ptr) { memset(onext, 0, sizeof(struct record)); } +#if CONFIG_HEAP_VALGRIND + VALGRIND_FREELIKE_BLOCK(ptr, REDZONE); +#endif + if (!heap_meta.unpausing && heap_meta.waiters.front && (heap_record_fits(prev2, &heap_meta.waiters.front->val, true) || |