From bbda77769d5be17206923d9b4944e2fbd463b3a7 Mon Sep 17 00:00:00 2001 From: Lephe Date: Thu, 10 Nov 2022 19:54:45 +0100 Subject: [PATCH] kmalloc: fix krealloc() not trying across arenas --- src/kmalloc/kmalloc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/kmalloc/kmalloc.c b/src/kmalloc/kmalloc.c index bb2d2ca..c734c32 100644 --- a/src/kmalloc/kmalloc.c +++ b/src/kmalloc/kmalloc.c @@ -112,6 +112,16 @@ void *krealloc(void *ptr, size_t size) else { a->stats.total_failures++; + + /* If reallocation within the original arena fails, try another + one. The memory copy behavior is sub-optimal (we copy the + new size which might be more than the original size) but + it's all we can do with this arena interface. */ + rc = kmalloc(size, NULL); + if(rc) + { + memcpy(rc, ptr, size); + } } return rc;