Fix crashes and memory leaks

This commit is contained in:
Theodore Dubois 2018-06-23 15:02:56 -07:00
parent 601ed99dc3
commit 1cf549de34
2 changed files with 8 additions and 2 deletions

View File

@ -38,6 +38,7 @@ void mem_release(struct mem *mem) {
pt_unmap(mem, 0, MEM_PAGES, PT_FORCE);
free(mem->pt);
write_wrunlock(&mem->lock);
jit_free(mem->jit);
free(mem);
}
}
@ -140,7 +141,9 @@ int pt_copy_on_write(struct mem *src, page_t src_start, struct mem *dst, page_t
entry->flags |= P_COW;
entry->flags &= ~P_COMPILED;
entry->data->refcount++;
dst->pt[dst_page] = *entry;
dst->pt[dst_page].data = entry->data;
dst->pt[dst_page].offset = entry->offset;
dst->pt[dst_page].flags = entry->flags;
}
}
mem_changed(src);

View File

@ -143,8 +143,11 @@ void cpu_run(struct cpu_state *cpu) {
read_wrunlock(&cpu->mem->lock);
handle_interrupt(interrupt);
read_wrlock(&cpu->mem->lock);
if (tlb->mem != cpu->mem)
if (tlb->mem != cpu->mem) {
tlb->mem = cpu->mem;
jit = cpu->mem->jit;
last_block = NULL;
}
if (cpu->mem->changes != changes) {
tlb_flush(tlb);
changes = cpu->mem->changes;