From dabd2355f355abd7d1d58641f6cc496adb1482d1 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sat, 14 Mar 2015 12:56:22 +0100 Subject: Add mutexes everywhere ; spam debug log (sorry) --- src/common/libkogata/slab_alloc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/common/libkogata') 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++; -- cgit v1.2.3