Add KORE_PENDANTIC_MALLOC option.

This option tells Kore to zero out memory when allocated, freed or
when get/put from the pools.
This commit is contained in:
Joris Vink 2014-04-22 12:46:23 +02:00
parent 39dd9d7972
commit d98d56fb20
4 changed files with 30 additions and 0 deletions

View File

@ -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

View File

@ -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 *,

View File

@ -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);
}

View File

@ -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));