kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 3e944e106b4cbcbd0a0d9a66ba4cddbc4876e615
parent a5342a0120dfaf4b4a20ca3b41788927c9fb43b8
Author: Joris Vink <joris@coders.se>
Date:   Wed,  1 Mar 2023 16:26:24 +0100

Change kore_realloc() behaviour a bit.

If kore_realloc() decides that a new block must be allocated it will
explicitly call the new kore_free_zero() function to erase the
contents of the old block once the move is done.

Diffstat:
include/kore/kore.h | 1+
src/mem.c | 20+++++++++++++++++---
2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/include/kore/kore.h b/include/kore/kore.h @@ -908,6 +908,7 @@ void *kore_calloc(size_t, size_t); void *kore_realloc(void *, size_t); void kore_free(void *); void kore_mem_init(void); +void kore_free_zero(void *); void kore_mem_cleanup(void); void kore_mem_untag(void *); void *kore_mem_lookup(u_int32_t); diff --git a/src/mem.c b/src/mem.c @@ -123,11 +123,11 @@ kore_realloc(void *ptr, size_t len) nptr = mem_alloc(len); } else { mem = meminfo(ptr); - if (len == mem->len) + if (len <= mem->len) return (ptr); nptr = mem_alloc(len); - memcpy(nptr, ptr, MIN(len, mem->len)); - kore_free(ptr); + memcpy(nptr, ptr, mem->len); + kore_free_zero(ptr); } return (nptr); @@ -150,6 +150,20 @@ kore_calloc(size_t memb, size_t len) } void +kore_free_zero(void *ptr) +{ + struct meminfo *mem; + + if (ptr == NULL) + return; + + mem = meminfo(ptr); + kore_mem_zero(ptr, mem->len); + + kore_free(ptr); +} + +void kore_free(void *ptr) { size_t idx;