mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 12:39:01 -04:00
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:
parent
39dd9d7972
commit
d98d56fb20
4
Makefile
4
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
|
||||
|
@ -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 *,
|
||||
|
14
src/mem.c
14
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);
|
||||
}
|
||||
|
@ -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));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user