(MESS) Homelab, vc4000, d6800: fixed memory leak

This commit is contained in:
Robbbert 2013-04-28 04:29:12 +00:00
parent 7a87b2b361
commit df1bd363d8
3 changed files with 115 additions and 94 deletions

View File

@ -338,11 +338,12 @@ QUICKLOAD_LOAD_MEMBER( d6800_state, d6800 )
{
address_space &space = m_maincpu->space(AS_PROGRAM);
int i;
int quick_addr = 0x0200;
int quick_addr = 0x200;
int exec_addr = 0xc000;
int quick_length;
UINT8 *quick_data;
int read_;
int result = IMAGE_INIT_FAIL;
quick_length = image.length();
quick_data = (UINT8*)malloc(quick_length);
@ -350,17 +351,17 @@ QUICKLOAD_LOAD_MEMBER( d6800_state, d6800 )
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
image.message(" Cannot open file");
return IMAGE_INIT_FAIL;
}
else
{
read_ = image.fread( quick_data, quick_length);
if (read_ != quick_length)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
image.message(" Cannot read the file");
return IMAGE_INIT_FAIL;
}
else
{
for (i = 0; i < quick_length; i++)
if ((quick_addr + i) < 0x800)
space.write_byte(i + quick_addr, quick_data[i]);
@ -370,7 +371,14 @@ QUICKLOAD_LOAD_MEMBER( d6800_state, d6800 )
// Start the quickload
m_maincpu->set_pc(exec_addr);
return IMAGE_INIT_PASS;
result = IMAGE_INIT_PASS;
}
free( quick_data );
}
return result;
}
static MACHINE_CONFIG_START( d6800, d6800_state )

View File

@ -10,6 +10,7 @@
ToDO:
- HTP files should be a cassette format, not a quickload.
- Quickloads cause the emulated machine to hang or reboot.
- homelab2 - cassette to fix.
Note that rom code 0x40-48 is meaningless garbage,
had to patch to stop it crashing. Need a new dump.
@ -661,6 +662,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
image.message(" Cannot open file");
free(quick_data);
return IMAGE_INIT_FAIL;
}
@ -669,6 +671,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
image.message(" Cannot read the file");
free(quick_data);
return IMAGE_INIT_FAIL;
}
@ -678,6 +681,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
image.message(" Invalid header");
free(quick_data);
return IMAGE_INIT_FAIL;
}
@ -687,6 +691,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File name too long");
image.message(" File name too long");
free(quick_data);
return IMAGE_INIT_FAIL;
}
@ -700,6 +705,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Unexpected EOF while getting file size");
image.message(" Unexpected EOF while getting file size");
free(quick_data);
return IMAGE_INIT_FAIL;
}
@ -711,6 +717,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too large");
image.message(" File too large");
free(quick_data);
return IMAGE_INIT_FAIL;
}
@ -726,11 +733,13 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
snprintf(message, ARRAY_LENGTH(message), "%s: Unexpected EOF while writing byte to %04X", pgmname, (unsigned) j);
image.seterror(IMAGE_ERROR_INVALIDIMAGE, message);
image.message("%s: Unexpected EOF while writing byte to %04X", pgmname, (unsigned) j);
free(quick_data);
return IMAGE_INIT_FAIL;
}
space.write_byte(j, ch);
}
free(quick_data);
return IMAGE_INIT_PASS;
}

View File

@ -533,6 +533,7 @@ QUICKLOAD_LOAD_MEMBER( vc4000_state,vc4000)
int quick_length;
UINT8 *quick_data;
int read_;
int result = IMAGE_INIT_FAIL;
quick_length = image.length();
quick_data = (UINT8*)malloc(quick_length);
@ -540,26 +541,26 @@ QUICKLOAD_LOAD_MEMBER( vc4000_state,vc4000)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
image.message(" Cannot open file");
return IMAGE_INIT_FAIL;
}
else
{
read_ = image.fread( quick_data, quick_length);
if (read_ != quick_length)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
image.message(" Cannot read the file");
return IMAGE_INIT_FAIL;
}
else
{
if (mame_stricmp(image.filetype(), "tvc")==0)
{
if (quick_data[0] != 2)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
image.message(" Invalid header");
return IMAGE_INIT_FAIL;
}
else
{
quick_addr = quick_data[1] * 256 + quick_data[2];
exec_addr = quick_data[3] * 256 + quick_data[4];
@ -575,7 +576,8 @@ QUICKLOAD_LOAD_MEMBER( vc4000_state,vc4000)
// Start the quickload
m_maincpu->set_pc(exec_addr);
return IMAGE_INIT_PASS;
result = IMAGE_INIT_PASS;
}
}
else
if (mame_stricmp(image.filetype(), "pgm")==0)
@ -584,33 +586,31 @@ QUICKLOAD_LOAD_MEMBER( vc4000_state,vc4000)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
image.message(" Invalid header");
return IMAGE_INIT_FAIL;
}
else
{
exec_addr = quick_data[1] * 256 + quick_data[2];
if (exec_addr >= quick_length)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
image.message(" Exec address beyond end of file");
return IMAGE_INIT_FAIL;
}
else
if (quick_length < 0x904)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
image.message(" File too short");
return IMAGE_INIT_FAIL;
}
else
// some programs store data in PVI memory and other random places. This is not supported.
if (quick_length > 0x1600)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
image.message(" File too long");
return IMAGE_INIT_FAIL;
}
else
{
for (i = quick_addr; i < quick_length; i++)
if (i < 0x1600)
space.write_byte(i, quick_data[i]);
@ -620,10 +620,14 @@ QUICKLOAD_LOAD_MEMBER( vc4000_state,vc4000)
// Start the quickload
m_maincpu->set_pc(exec_addr);
return IMAGE_INIT_PASS;
result = IMAGE_INIT_PASS;
}
else
return IMAGE_INIT_FAIL;
}
}
}
free (quick_data);
}
return result;
}