- memory cleanup code moved to a separate method (called from bx_atexit())

- fixed memory handler init and cleanup code (memory leaks)
This commit is contained in:
Volker Ruppert 2006-09-15 17:02:52 +00:00
parent 38caf3bf19
commit 0a804aeb18
3 changed files with 38 additions and 30 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: main.cc,v 1.341 2006-09-10 09:13:47 vruppert Exp $
// $Id: main.cc,v 1.342 2006-09-15 17:02:52 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -1146,6 +1146,8 @@ int bx_atexit(void)
}
#endif
BX_MEM(0)->cleanup_memory();
#if BX_PROVIDE_DEVICE_MODELS==1
bx_pc_system.exit();
#endif

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: memory.h,v 1.39 2006-09-02 12:08:28 vruppert Exp $
// $Id: memory.h,v 1.40 2006-09-15 17:02:52 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -85,6 +85,7 @@ public:
~BX_MEM_C();
BX_MEM_SMF void alloc_vector_aligned (size_t bytes, size_t alignment) BX_CPP_AttrRegparmN(2);
BX_MEM_SMF void init_memory(int memsize);
BX_MEM_SMF void cleanup_memory(void);
BX_MEM_SMF void enable_smram(bx_bool enable, bx_bool restricted);
BX_MEM_SMF void disable_smram(void);
BX_MEM_SMF bx_bool is_smram_accessible(void);

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: misc_mem.cc,v 1.96 2006-09-02 12:08:28 vruppert Exp $
// $Id: misc_mem.cc,v 1.97 2006-09-15 17:02:52 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -83,41 +83,19 @@ BX_MEM_C::alloc_vector_aligned (size_t bytes, size_t alignment)
BX_MEM_C::~BX_MEM_C()
{
if (BX_MEM_THIS vector != NULL) {
delete [] BX_MEM_THIS actual_vector;
BX_MEM_THIS actual_vector = NULL;
BX_MEM_THIS vector = NULL;
delete [] BX_MEM_THIS memory_handlers;
BX_MEM_THIS memory_handlers = NULL;
#if BX_DEBUGGER
delete [] BX_MEM_THIS dbg_dirty_pages;
#endif
} else {
BX_DEBUG(("Memory not freed as it wasn't allocated !"));
}
cleanup_memory();
}
void BX_MEM_C::init_memory(int memsize)
{
unsigned idx;
BX_DEBUG(("Init $Id: misc_mem.cc,v 1.96 2006-09-02 12:08:28 vruppert Exp $"));
BX_DEBUG(("Init $Id: misc_mem.cc,v 1.97 2006-09-15 17:02:52 vruppert Exp $"));
if (BX_MEM_THIS vector != NULL) {
delete [] BX_MEM_THIS actual_vector;
BX_MEM_THIS actual_vector = NULL;
BX_MEM_THIS vector = NULL;
delete [] BX_MEM_THIS memory_handlers;
BX_MEM_THIS memory_handlers = NULL;
#if BX_DEBUGGER
delete [] BX_MEM_THIS dbg_dirty_pages;
#endif
}
alloc_vector_aligned (memsize+ BIOSROMSZ + EXROMSIZE + 4096, BX_MEM_VECTOR_ALIGN);
alloc_vector_aligned(memsize+ BIOSROMSZ + EXROMSIZE + 4096, BX_MEM_VECTOR_ALIGN);
BX_MEM_THIS len = memsize;
BX_MEM_THIS megabytes = memsize / (1024*1024);
BX_MEM_THIS memory_handlers = new struct memory_handler_struct *[1024 * 1024];
BX_MEM_THIS memory_handlers = new struct memory_handler_struct *[4096];
BX_MEM_THIS rom = &BX_MEM_THIS vector[memsize];
BX_MEM_THIS bogus = &BX_MEM_THIS vector[memsize + BIOSROMSZ + EXROMSIZE];
#if BX_DEBUGGER
@ -127,7 +105,7 @@ void BX_MEM_C::init_memory(int memsize)
#endif
memset(BX_MEM_THIS rom, 0xff, BIOSROMSZ + EXROMSIZE);
memset(BX_MEM_THIS bogus, 0xff, 4096);
for (idx = 0; idx < 1024 * 1024; idx++)
for (idx = 0; idx < 4096; idx++)
BX_MEM_THIS memory_handlers[idx] = NULL;
for (idx = 0; idx < 65; idx++)
BX_MEM_THIS rom_present[idx] = 0;
@ -146,6 +124,33 @@ void BX_MEM_C::init_memory(int memsize)
#endif
}
void BX_MEM_C::cleanup_memory()
{
unsigned idx;
if (BX_MEM_THIS vector != NULL) {
delete [] BX_MEM_THIS actual_vector;
BX_MEM_THIS actual_vector = NULL;
BX_MEM_THIS vector = NULL;
if (BX_MEM_THIS memory_handlers != NULL) {
for (idx = 0; idx < 4096; idx++) {
struct memory_handler_struct *memory_handler = BX_MEM_THIS memory_handlers[idx];
struct memory_handler_struct *prev = NULL;
while (memory_handler) {
prev = memory_handler;
memory_handler = memory_handler->next;
delete prev;
}
}
delete [] BX_MEM_THIS memory_handlers;
BX_MEM_THIS memory_handlers = NULL;
}
#if BX_DEBUGGER
delete [] BX_MEM_THIS dbg_dirty_pages;
#endif
}
}
#if BX_SUPPORT_APIC
void put_8bit(Bit8u **pp, Bit8u value)
{