commit f18a6388fd895e7ce0e71f3e94550d23d8be6512
parent 4b2420097b7eb5c1511ded8f4116ba449a7adb71
Author: Joris Vink <joris@coders.se>
Date: Thu, 27 Jun 2013 09:20:48 +0200
fix kore_realloc() to actually behave properly
Diffstat:
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/src/mem.c b/src/mem.c
@@ -97,16 +97,19 @@ kore_realloc(void *ptr, size_t len)
struct meminfo *mem;
void *nptr;
- mem = KORE_MEMINFO(ptr);
- if (mem->magic != KORE_MEM_MAGIC)
- fatal("kore_realloc(): magic boundary not found");
-
- nptr = kore_malloc(len);
- memcpy(nptr, mem->addr, mem->clen);
- kore_mem_free(mem);
-
- mem = (struct meminfo *)nptr - sizeof(*mem);
- return (mem->addr);
+ if (ptr == NULL) {
+ nptr = kore_malloc(len);
+ } else {
+ mem = KORE_MEMINFO(ptr);
+ if (mem->magic != KORE_MEM_MAGIC)
+ fatal("kore_realloc(): magic boundary not found");
+
+ nptr = kore_malloc(len);
+ memcpy(nptr, ptr, mem->clen);
+ kore_mem_free(ptr);
+ }
+
+ return (nptr);
}
void *