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 d98d56fb209fb0d9c94872fdd7c7c5834d5a0ef6
parent 39dd9d79726cc2ee7a6d94521c93a321100fcef0
Author: Joris Vink <joris@coders.se>
Date:   Tue, 22 Apr 2014 12:46:23 +0200

Add KORE_PENDANTIC_MALLOC option.

This option tells Kore to zero out memory when allocated, freed or
when get/put from the pools.

Diffstat:
Makefile | 4++++
includes/kore.h | 4++++
src/mem.c | 14++++++++++++++
src/pool.c | 8++++++++
4 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -18,6 +18,10 @@ ifneq ("$(DEBUG)", "") CFLAGS+=-DKORE_DEBUG endif +ifneq ("$(KORE_PEDANTIC_MALLOC)", "") + CFLAGS+=-DKORE_PEDANTIC_MALLOC +endif + ifneq ("$(PGSQL)", "") S_SRC+=contrib/postgres/kore_pgsql.c LDFLAGS+=-L$(shell pg_config --libdir) -lpq diff --git a/includes/kore.h b/includes/kore.h @@ -387,6 +387,10 @@ void *kore_realloc(void *, size_t); void kore_mem_free(void *); void kore_mem_init(void); +#if defined(KORE_PEDANTIC_MALLOC) +void explicit_bzero(void *, size_t); +#endif + void *kore_pool_get(struct kore_pool *); void kore_pool_put(struct kore_pool *, void *); void kore_pool_init(struct kore_pool *, char *, diff --git a/src/mem.c b/src/mem.c @@ -55,6 +55,10 @@ kore_malloc(size_t len) mem = KORE_MEMINFO(addr); mem->magic = KORE_MEM_MAGIC; +#if defined(KORE_PEDANTIC_MALLOC) + explicit_bzero(addr, len); +#endif + return (addr); } @@ -95,6 +99,10 @@ kore_mem_free(void *ptr) if (mem->magic != KORE_MEM_MAGIC) fatal("kore_mem_free(): magic boundary not found"); +#if defined(KORE_PEDANTIC_MALLOC) + explicit_bzero(ptr, KORE_MEMSIZE(ptr)); +#endif + addr = (u_int8_t *)ptr - sizeof(u_int32_t); free(addr); } @@ -111,3 +119,9 @@ kore_strdup(const char *str) return (nstr); } + +void +explicit_bzero(void *addr, size_t len) +{ + bzero(addr, len); +} diff --git a/src/pool.c b/src/pool.c @@ -63,6 +63,10 @@ kore_pool_get(struct kore_pool *pool) pool->inuse++; +#if defined(KORE_PEDANTIC_MALLOC) + explicit_bzero(ptr, pool->elen); +#endif + return (ptr); } @@ -71,6 +75,10 @@ kore_pool_put(struct kore_pool *pool, void *ptr) { struct kore_pool_entry *entry; +#if defined(KORE_PEDANTIC_MALLOC) + explicit_bzero(ptr, pool->elen); +#endif + entry = (struct kore_pool_entry *) ((u_int8_t *)ptr - sizeof(struct kore_pool_entry));