diff options
author | Alex Auvolat <alex@adnab.me> | 2015-03-14 12:56:22 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2015-03-14 12:56:22 +0100 |
commit | dabd2355f355abd7d1d58641f6cc496adb1482d1 (patch) | |
tree | 48f674f68b5ec2314d4dd7735af0db0af3408c49 /src/common | |
parent | 151edb44eea9bf25ec466133e9dbef87bd6b1372 (diff) | |
download | kogata-dabd2355f355abd7d1d58641f6cc496adb1482d1.tar.gz kogata-dabd2355f355abd7d1d58641f6cc496adb1482d1.zip |
Add mutexes everywhere ; spam debug log (sorry)
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/libalgo/hashtbl.c | 3 | ||||
-rw-r--r-- | src/common/libkogata/slab_alloc.c | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/common/libalgo/hashtbl.c b/src/common/libalgo/hashtbl.c index 13185c2..6fb5b60 100644 --- a/src/common/libalgo/hashtbl.c +++ b/src/common/libalgo/hashtbl.c @@ -1,3 +1,4 @@ +#include <debug.h> #include <malloc.h> #include <hashtbl.h> @@ -68,7 +69,7 @@ void hashtbl_check_size(hashtbl_t *ht) { if (nsize != 0) { hashtbl_item_t **nitems = (hashtbl_item_t**)malloc(nsize * sizeof(hashtbl_item_t*)); - if (nitems == 0) return; // if we can't realloc, too bad, we just lose space + if (nitems == 0) return; // if we can't realloc, too bad, we just lose space/efficienty for (size_t i = 0; i < nsize; i++) nitems[i] = 0; diff --git a/src/common/libkogata/slab_alloc.c b/src/common/libkogata/slab_alloc.c index 837a965..daa3a50 100644 --- a/src/common/libkogata/slab_alloc.c +++ b/src/common/libkogata/slab_alloc.c @@ -235,6 +235,18 @@ void slab_free(mem_allocator_t* a, void* addr) { ASSERT((addr - r->region_addr) % a->types[i].obj_size == 0); object_t *o = (object_t*)addr; + + // check the object is not already on the free list (double-free error) + for (object_t *i = r->first_free_obj; i != 0; i = i->next) { + if (!((void*)i >= r->region_addr && (void*)i < r->region_addr + region_size)){ + dbg_printf("Invalid object 0x%p in cache 0x%p - %x\n", i, r->region_addr, region_size); + PANIC("Error"); + } + ASSERT(o != i); + } + + /*dbg_printf("Put back 0x%p in 0x%p\n", o, r->region_addr);*/ + o->next = r->first_free_obj; r->first_free_obj = o; r->n_free_objs++; |