diff --git a/kernel/mem/alloc.c b/kernel/mem/alloc.c index 6ff3e970..7af7844c 100644 --- a/kernel/mem/alloc.c +++ b/kernel/mem/alloc.c @@ -292,6 +292,10 @@ void free(void * ptr) { x = (uint32_t *)tag; break; } + page_t * page = get_page((uintptr_t)x, 0, current_directory); + if (page->present != 1) break; + page = get_page((uintptr_t)x + 8, 0, current_directory); + if (page->present != 1) break; if (*x == 0xDEADBEEF) { if (x[1] == i) { _failed = 0; diff --git a/util/process_log.py b/util/process_log.py index ce4e525d..dc47d42f 100644 --- a/util/process_log.py +++ b/util/process_log.py @@ -5,9 +5,16 @@ addresses = {} sources = {} last_touched = {} -def find_nearby_allocations(addr): +def find_nearby_allocations(addr,size): + results = [] for key in addresses.keys(): - if abs(addr - key) < 0x100 and addresses[key]: + if abs(addr - key) < size*2 and addresses[key]: + results.append(key) + results = sorted(results) + for key in results: + if key == addr: + print(" self: 0x%x (size %d, allocated by 0x%x)" % (key, addresses[key], sources[key])) + else: print(" nearby: 0x%x (size %d, allocated by 0x%x)" % (key, addresses[key], sources[key])) count = 0 @@ -56,7 +63,7 @@ while 1: print("Large buffer has bad value: 0x%x (0x%x) expected size is %d, supposed is %d" % (addr, extra, addresses[addr], size)) elif addresses[addr] != size: print("Size on free is incorrect: 0x%x %d %d 0x%x allocated by 0x%x last touched by %c" % (addr,addresses[addr], size, fault, sources[addr], last_touched[addr])) - find_nearby_allocations(addr) + find_nearby_allocations(addr,addresses[addr]) else: addresses[addr] = None elif t == 'h':