replaced some more malloc/free usage with global_alloc_array/global_free_array (nw)

This commit is contained in:
Oliver Stöneberg 2014-03-28 15:32:15 +00:00
parent 513738066d
commit f963d0bcd7
26 changed files with 83 additions and 84 deletions

View File

@ -2090,11 +2090,10 @@ ROM_END
void astra_addresslines( UINT16* src, size_t srcsize, int small )
{
UINT16 *dst = (UINT16*)malloc(srcsize);
UINT16 *dst = global_alloc_array(UINT16, srcsize/2);
int blocksize;
if (small) blocksize= 0x100000/2;
else blocksize= 0x100000;
@ -2108,7 +2107,7 @@ void astra_addresslines( UINT16* src, size_t srcsize, int small )
}
memcpy(src,dst, srcsize);
free(dst);
global_free_array(dst);
}

View File

@ -246,7 +246,7 @@ QUICKLOAD_LOAD_MEMBER( binbug_state, binbug )
}
else
{
quick_data = (UINT8*)malloc(quick_length);
quick_data = global_alloc_array(UINT8, quick_length);
if (!quick_data)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
@ -290,7 +290,7 @@ QUICKLOAD_LOAD_MEMBER( binbug_state, binbug )
}
}
free( quick_data );
global_free_array(quick_data);
}
return result;

View File

@ -217,7 +217,7 @@ QUICKLOAD_LOAD_MEMBER( cd2650_state, cd2650 )
}
else
{
UINT8 *quick_data = (UINT8*)malloc(quick_length);
UINT8 *quick_data = global_alloc_array(UINT8, quick_length);
if (!quick_data)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
@ -271,7 +271,7 @@ QUICKLOAD_LOAD_MEMBER( cd2650_state, cd2650 )
}
}
free( quick_data );
global_free_array(quick_data);
}
return result;

View File

@ -351,7 +351,7 @@ QUICKLOAD_LOAD_MEMBER( d6800_state, d6800 )
int result = IMAGE_INIT_FAIL;
quick_length = image.length();
quick_data = (UINT8*)malloc(quick_length);
quick_data = global_alloc_array(UINT8, quick_length);
if (!quick_data)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
@ -383,7 +383,7 @@ QUICKLOAD_LOAD_MEMBER( d6800_state, d6800 )
result = IMAGE_INIT_PASS;
}
free( quick_data );
global_free_array(quick_data);
}
return result;

View File

@ -657,12 +657,11 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
int read_;
quick_length = image.length();
quick_data = (UINT8*)malloc(quick_length);
quick_data = global_alloc_array(UINT8, quick_length);
if (!quick_data)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
image.message(" Cannot open file");
free(quick_data);
return IMAGE_INIT_FAIL;
}
@ -671,7 +670,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);
global_free_array(quick_data);
return IMAGE_INIT_FAIL;
}
@ -681,7 +680,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
image.message(" Invalid header");
free(quick_data);
global_free_array(quick_data);
return IMAGE_INIT_FAIL;
}
@ -691,7 +690,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);
global_free_array(quick_data);
return IMAGE_INIT_FAIL;
}
@ -705,7 +704,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);
global_free_array(quick_data);
return IMAGE_INIT_FAIL;
}
@ -717,7 +716,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too large");
image.message(" File too large");
free(quick_data);
global_free_array(quick_data);
return IMAGE_INIT_FAIL;
}
@ -733,13 +732,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);
global_free_array(quick_data);
return IMAGE_INIT_FAIL;
}
space.write_byte(j, ch);
}
free(quick_data);
global_free_array(quick_data);
return IMAGE_INIT_PASS;
}

View File

@ -339,7 +339,7 @@ QUICKLOAD_LOAD_MEMBER( instruct_state, instruct )
}
else
{
UINT8* quick_data = (UINT8*)malloc(quick_length);
UINT8* quick_data = global_alloc_array(UINT8, quick_length);
if (!quick_data)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
@ -405,7 +405,7 @@ QUICKLOAD_LOAD_MEMBER( instruct_state, instruct )
}
}
free( quick_data );
global_free_array(quick_data);
}
return result;

View File

@ -167,18 +167,18 @@ QUICKLOAD_LOAD_MEMBER( lynx_state, lynx )
length = header[5] | (header[4]<<8);
length -= 10;
data = (UINT8*)malloc(length);
data = global_alloc_array(UINT8, length);
if (image.fread( data, length) != length)
{
free(data);
global_free_array(data);
return IMAGE_INIT_FAIL;
}
for (i = 0; i < length; i++)
space.write_byte(start + i, data[i]);
free(data);
global_free_array(data);
rom[0x1fc] = start & 0xff;
rom[0x1fd] = start >> 8;

View File

@ -296,7 +296,7 @@ QUICKLOAD_LOAD_MEMBER( phunsy_state, phunsy )
}
else
{
quick_data = (UINT8*)malloc(quick_length);
quick_data = global_alloc_array(UINT8, quick_length);
if (!quick_data)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
@ -324,7 +324,7 @@ QUICKLOAD_LOAD_MEMBER( phunsy_state, phunsy )
result = IMAGE_INIT_PASS;
}
free( quick_data );
global_free_array(quick_data);
}
return result;

View File

@ -113,7 +113,7 @@ QUICKLOAD_LOAD_MEMBER( pipbug_state, pipbug )
}
else
{
quick_data = (UINT8*)malloc(quick_length);
quick_data = global_alloc_array(UINT8, quick_length);
if (!quick_data)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
@ -157,7 +157,7 @@ QUICKLOAD_LOAD_MEMBER( pipbug_state, pipbug )
}
}
free( quick_data );
global_free_array(quick_data);
}
return result;

View File

@ -392,7 +392,7 @@ int psx1_state::load_psf( cpu_device *cpu, unsigned char *p_n_file, int n_len )
}
n_uncompressed = 0x200000;
p_n_uncompressed = (unsigned char *)malloc( n_uncompressed );
p_n_uncompressed = global_alloc_array( unsigned char, n_uncompressed );
if( uncompress( p_n_uncompressed, &n_uncompressed, p_n_compressed, n_compressed ) != Z_OK )
{
@ -407,7 +407,7 @@ int psx1_state::load_psf( cpu_device *cpu, unsigned char *p_n_file, int n_len )
n_return = 1;
}
free( p_n_uncompressed );
global_free_array( p_n_uncompressed );
}
return n_return;
}
@ -439,7 +439,7 @@ DIRECT_UPDATE_MEMBER(psx1_state::psx_setopbase)
}
m_exe_size = 0;
free( m_exe_buffer );
global_free_array( m_exe_buffer );
}
return address;
}
@ -449,7 +449,7 @@ QUICKLOAD_LOAD_MEMBER( psx1_state, psx_exe_load )
address_space &space = m_maincpu->space( AS_PROGRAM );
m_exe_size = 0;
m_exe_buffer = (UINT8*)malloc( quickload_size );
m_exe_buffer = global_alloc_array( UINT8, quickload_size );
if( m_exe_buffer == NULL )
{
logerror( "psx_exe_load: out of memory\n" );
@ -457,7 +457,7 @@ QUICKLOAD_LOAD_MEMBER( psx1_state, psx_exe_load )
}
if( image.fread( m_exe_buffer, quickload_size ) != quickload_size )
{
free( m_exe_buffer );
global_free_array( m_exe_buffer );
return IMAGE_INIT_FAIL;
}
m_exe_size = quickload_size;

View File

@ -289,7 +289,7 @@ QUICKLOAD_LOAD_MEMBER( ravens_state, ravens )
}
else
{
quick_data = (UINT8*)malloc(quick_length);
quick_data = global_alloc_array(UINT8, quick_length);
if (!quick_data)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
@ -333,7 +333,7 @@ QUICKLOAD_LOAD_MEMBER( ravens_state, ravens )
}
}
free( quick_data );
global_free_array(quick_data);
}
return result;

View File

@ -637,7 +637,7 @@ DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart )
return IMAGE_INIT_FAIL;
}
file_data = (UINT8 *)malloc(file_size);
file_data = global_alloc_array(UINT8, file_size);
if (file_data == NULL)
{
logerror ("Memory allocating error\n");
@ -651,7 +651,7 @@ DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart )
if (chunks_in_file*0x2000+0x09 != file_size)
{
free (file_data);
global_free_array(file_data);
logerror ("File corrupted\n");
return IMAGE_INIT_FAIL;
}
@ -660,10 +660,10 @@ DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart )
{
case 0x00: logerror ("DOCK cart\n");
timex_cart.type = TIMEX_CART_DOCK;
timex_cart.data = (UINT8*) malloc (0x10000);
timex_cart.data = global_alloc_array(UINT8, 0x10000);
if (!timex_cart.data)
{
free (file_data);
global_free_array(file_data);
logerror ("Memory allocate error\n");
return IMAGE_INIT_FAIL;
}
@ -684,11 +684,11 @@ DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart )
memset (timex_cart.data+i*0x2000, 0xff, 0x2000);
}
}
free (file_data);
global_free_array(file_data);
break;
default: logerror ("Cart type not supported\n");
free (file_data);
global_free_array(file_data);
timex_cart.type = TIMEX_CART_NONE;
return IMAGE_INIT_FAIL;
}
@ -703,7 +703,7 @@ DEVICE_IMAGE_UNLOAD_MEMBER( spectrum_state, timex_cart )
{
if (timex_cart.data)
{
free (timex_cart.data);
global_free_array(timex_cart.data);
timex_cart.data = NULL;
}
timex_cart.type = TIMEX_CART_NONE;

View File

@ -563,7 +563,7 @@ QUICKLOAD_LOAD_MEMBER( vc4000_state,vc4000)
int result = IMAGE_INIT_FAIL;
quick_length = image.length();
quick_data = (UINT8*)malloc(quick_length);
quick_data = global_alloc_array(UINT8, quick_length);
if (!quick_data)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
@ -678,7 +678,7 @@ QUICKLOAD_LOAD_MEMBER( vc4000_state,vc4000)
}
}
}
free (quick_data);
global_free_array(quick_data);
}
return result;
}

View File

@ -3155,7 +3155,7 @@ SNAPSHOT_LOAD_MEMBER( amstrad_state,amstrad)
if (snapshot_size < 8)
return IMAGE_INIT_FAIL;
snapshot = (UINT8 *)malloc(snapshot_size);
snapshot = global_alloc_array(UINT8, snapshot_size);
if (!snapshot)
return IMAGE_INIT_FAIL;
@ -3164,12 +3164,12 @@ SNAPSHOT_LOAD_MEMBER( amstrad_state,amstrad)
if (memcmp(snapshot, "MV - SNA", 8))
{
free(snapshot);
global_free_array(snapshot);
return IMAGE_INIT_FAIL;
}
amstrad_handle_snapshot(snapshot);
free(snapshot);
global_free_array(snapshot);
return IMAGE_INIT_PASS;
}

View File

@ -32,7 +32,7 @@ private:
struct atari_drive
{
UINT8 *image; /* malloc'd image */
UINT8 *image; /* alloc'd image */
int type; /* type of image (XFD, ATR, DSK) */
int mode; /* 0 read only, != 0 read/write */
int density; /* 0 SD, 1 MD, 2 DD */

View File

@ -69,7 +69,7 @@ int general_cbm_loadsnap( device_image_interface &image, const char *file_type,
address = 2049;
snapshot_size -= 2;
data = (UINT8*)malloc(snapshot_size);
data = global_alloc_array(UINT8, snapshot_size);
if (!data)
goto error;
@ -81,12 +81,12 @@ int general_cbm_loadsnap( device_image_interface &image, const char *file_type,
space.write_byte(address + i + offset, data[i]);
cbm_sethiaddress(space, address + snapshot_size);
free(data);
global_free_array(data);
return IMAGE_INIT_PASS;
error:
if (data)
free(data);
global_free_array(data);
return IMAGE_INIT_FAIL;
}

View File

@ -992,7 +992,7 @@ void hp48_port_image_device::hp48_fill_port()
struct hp48_port_interface* conf = (struct hp48_port_interface*) static_config();
int size = state->m_port_size[conf->port];
LOG(( "hp48_fill_port: %s module=%i size=%i rw=%i\n", tag(), conf->module, size, state->m_port_write[conf->port] ));
state->m_port_data[conf->port] = (UINT8*)malloc( 2 * size );
state->m_port_data[conf->port] = global_alloc_array(UINT8, 2 * size);
memset( state->m_port_data[conf->port], 0, 2 * size );
state->m_modules[conf->module].off_mask = 2 * (( size > 128 * 1024 ) ? 128 * 1024 : size) - 1;
state->m_modules[conf->module].read = read8_delegate();
@ -1072,7 +1072,7 @@ void hp48_port_image_device::call_unload()
fseek( 0, SEEK_SET );
fwrite( state->m_port_data[conf->port], state->m_port_size[conf->port] );
}
free( state->m_port_data[conf->port] );
global_free_array( state->m_port_data[conf->port] );
hp48_unfill_port();
state->hp48_apply_modules();
}

View File

@ -323,7 +323,7 @@ SNAPSHOT_LOAD_MEMBER( lviv_state, lviv )
{
UINT8 *lviv_snapshot_data;
lviv_snapshot_data = (UINT8*)malloc(LVIV_SNAPSHOT_SIZE);
lviv_snapshot_data = global_alloc_array(UINT8, LVIV_SNAPSHOT_SIZE);
if (!lviv_snapshot_data)
{
logerror ("Unable to load snapshot file\n");
@ -334,7 +334,7 @@ SNAPSHOT_LOAD_MEMBER( lviv_state, lviv )
if(lviv_verify_snapshot(lviv_snapshot_data, snapshot_size) == IMAGE_VERIFY_FAIL)
{
free(lviv_snapshot_data);
global_free_array(lviv_snapshot_data);
return IMAGE_INIT_FAIL;
}
@ -342,7 +342,7 @@ SNAPSHOT_LOAD_MEMBER( lviv_state, lviv )
dump_registers();
free(lviv_snapshot_data);
global_free_array(lviv_snapshot_data);
logerror("Snapshot file loaded\n");
return IMAGE_INIT_PASS;

View File

@ -840,7 +840,7 @@ QUICKLOAD_LOAD_MEMBER( microtan_state, microtan )
int rc;
snapshot_size = 8263; /* magic size */
snapshot_buff = (UINT8*)malloc(snapshot_size);
snapshot_buff = global_alloc_array(UINT8, snapshot_size);
if (!snapshot_buff)
{
logerror("microtan_hexfile_load: could not allocate %d bytes of buffer\n", snapshot_size);
@ -848,10 +848,10 @@ QUICKLOAD_LOAD_MEMBER( microtan_state, microtan )
}
memset(snapshot_buff, 0, snapshot_size);
buff = (char*)malloc(quickload_size + 1);
buff = global_alloc_array(char, quickload_size + 1);
if (!buff)
{
free(snapshot_buff);
global_free_array(snapshot_buff);
logerror("microtan_hexfile_load: could not allocate %d bytes of buffer\n", quickload_size);
return IMAGE_INIT_FAIL;
}
@ -865,6 +865,7 @@ QUICKLOAD_LOAD_MEMBER( microtan_state, microtan )
rc = parse_zillion_hex(snapshot_buff, buff);
if (rc == IMAGE_INIT_PASS)
microtan_snapshot_copy(snapshot_buff, snapshot_size);
free(snapshot_buff);
global_free_array(buff);
global_free_array(snapshot_buff);
return rc;
}

View File

@ -61,8 +61,8 @@ int nc_state::nc_card_load(device_image_interface &image, unsigned char **ptr)
if (datasize!=0)
{
/* malloc memory for this data */
data = (unsigned char *)malloc(datasize);
/* alloc memory for this data */
data = global_alloc_array(unsigned char, datasize);
if (data!=NULL)
{
@ -130,7 +130,7 @@ DEVICE_IMAGE_UNLOAD_MEMBER( nc_state, nc_pcmcia_card )
/* free ram allocated to card */
if (m_card_ram!=NULL)
{
free(m_card_ram);
global_free_array(m_card_ram);
m_card_ram = NULL;
}
m_card_size = 0;

View File

@ -301,24 +301,24 @@ SNAPSHOT_LOAD_MEMBER( primo_state, primo )
{
UINT8 *snapshot_data;
if (!(snapshot_data = (UINT8*) malloc(snapshot_size)))
if (!(snapshot_data = global_alloc_array(UINT8, snapshot_size)))
return IMAGE_INIT_FAIL;
if (image.fread( snapshot_data, snapshot_size) != snapshot_size)
{
free(snapshot_data);
global_free_array(snapshot_data);
return IMAGE_INIT_FAIL;
}
if (strncmp((char *)snapshot_data, "PS01", 4))
{
free(snapshot_data);
global_free_array(snapshot_data);
return IMAGE_INIT_FAIL;
}
primo_setup_pss(snapshot_data, snapshot_size);
free(snapshot_data);
global_free_array(snapshot_data);
return IMAGE_INIT_PASS;
}
@ -352,17 +352,17 @@ QUICKLOAD_LOAD_MEMBER( primo_state, primo )
{
UINT8 *quickload_data;
if (!(quickload_data = (UINT8*) malloc(quickload_size)))
if (!(quickload_data = global_alloc_array(UINT8, quickload_size)))
return IMAGE_INIT_FAIL;
if (image.fread( quickload_data, quickload_size) != quickload_size)
{
free(quickload_data);
global_free_array(quickload_data);
return IMAGE_INIT_FAIL;
}
primo_setup_pp(quickload_data, quickload_size);
free(quickload_data);
global_free_array(quickload_data);
return IMAGE_INIT_PASS;
}

View File

@ -114,7 +114,7 @@ SNAPSHOT_LOAD_MEMBER( spectrum_state,spectrum)
{
UINT8 *snapshot_data = NULL;
snapshot_data = (UINT8*)malloc(snapshot_size);
snapshot_data = global_alloc_array(UINT8, snapshot_size);
if (!snapshot_data)
goto error;
@ -233,13 +233,13 @@ SNAPSHOT_LOAD_MEMBER( spectrum_state,spectrum)
spectrum_setup_z80(machine(), snapshot_data, snapshot_size);
}
free(snapshot_data);
global_free_array(snapshot_data);
return IMAGE_INIT_PASS;
error:
if (snapshot_data)
free(snapshot_data);
global_free_array(snapshot_data);
return IMAGE_INIT_FAIL;
}
@ -2455,7 +2455,7 @@ QUICKLOAD_LOAD_MEMBER( spectrum_state,spectrum)
{
UINT8 *quickload_data = NULL;
quickload_data = (UINT8*)malloc(quickload_size);
quickload_data = global_alloc_array(UINT8, quickload_size);
if (!quickload_data)
goto error;
@ -2480,13 +2480,13 @@ QUICKLOAD_LOAD_MEMBER( spectrum_state,spectrum)
spectrum_setup_raw(machine(), quickload_data, quickload_size);
}
free(quickload_data);
global_free_array(quickload_data);
return IMAGE_INIT_PASS;
error:
if (quickload_data)
free(quickload_data);
global_free_array(quickload_data);
return IMAGE_INIT_FAIL;
}

View File

@ -694,7 +694,7 @@ SNAPSHOT_LOAD_MEMBER( ti85_state, ti8x )
return IMAGE_INIT_FAIL;
}
if (!(ti8x_snapshot_data = (UINT8*)malloc(snapshot_size)))
if (!(ti8x_snapshot_data = global_alloc_array(UINT8, snapshot_size)))
return IMAGE_INIT_FAIL;
image.fread( ti8x_snapshot_data, snapshot_size);
@ -704,6 +704,6 @@ SNAPSHOT_LOAD_MEMBER( ti85_state, ti8x )
else if (!strncmp(machine().system().name, "ti86", 4))
ti86_setup_snapshot(ti8x_snapshot_data);
free(ti8x_snapshot_data);
global_free_array(ti8x_snapshot_data);
return IMAGE_INIT_PASS;
}

View File

@ -392,7 +392,7 @@ void ti99_datamux_device::device_start(void)
void ti99_datamux_device::device_stop(void)
{
if (m_ram16b) free(m_ram16b);
if (m_ram16b) global_free_array(m_ram16b);
}
void ti99_datamux_device::device_reset(void)
@ -410,7 +410,7 @@ void ti99_datamux_device::device_reset(void)
// better use a region?
if (m_ram16b==NULL)
{
m_ram16b = (UINT16*)malloc(32768);
m_ram16b = global_alloc_array(UINT16, 32768/2);
memset(m_ram16b, 0, 32768);
}

View File

@ -2337,7 +2337,7 @@ rpk* rpk_reader::open(emu_options &options, const char *filename, const char *sy
if (header == NULL) throw rpk_exception(RPK_MISSING_LAYOUT);
/* reserve space for the layout file contents (+1 for the termination) */
layout_text = (char*)malloc(header->uncompressed_length + 1);
layout_text = global_alloc_array(char, header->uncompressed_length + 1);
if (layout_text == NULL) throw rpk_exception(RPK_OUT_OF_MEMORY);
/* uncompress the layout text */
@ -2429,14 +2429,14 @@ rpk* rpk_reader::open(emu_options &options, const char *filename, const char *sy
{
newrpk->close();
if (zipfile != NULL) zip_file_close(zipfile);
if (layout_text != NULL) free(layout_text);
if (layout_text != NULL) global_free_array(layout_text);
// rethrow the exception
throw exp;
}
if (zipfile != NULL) zip_file_close(zipfile);
if (layout_text != NULL) free(layout_text);
if (layout_text != NULL) global_free_array(layout_text);
return newrpk;
}

View File

@ -265,11 +265,11 @@ WRITE16_MEMBER( x68k_hdc_image_device::hdc_w )
lba |= m_command[2] << 8;
lba |= (m_command[1] & 0x1f) << 16;
fseek(lba * 256,SEEK_SET);
blk = (char*)malloc(256*33);
blk = global_alloc_array(char, 256*33);
memset(blk,0,256*33);
// formats 33 256-byte blocks
fwrite(blk,256*33);
free(blk);
global_free_array(blk);
logerror("SASI: FORMAT UNIT (LBA 0x%06x)\n",lba);
break;
default: