Skip to content

Commit

Permalink
Switch to using libspectrum_realloc over raw realloc.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredm committed Jun 7, 2012
1 parent c129126 commit ef2bcf5
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 44 deletions.
12 changes: 4 additions & 8 deletions fuse/display.c
Expand Up @@ -137,14 +137,10 @@ alloc_change(void)

if( border_changes_size == border_changes_last ) {
border_changes_size += 10;
border_changes = realloc( border_changes,
border_changes_size*
sizeof( struct border_change_t )
);
if( !border_changes ) {
ui_error( UI_ERROR_ERROR, "out of memory at %s:%d", __FILE__, __LINE__ );
fuse_abort();
}
border_changes = libspectrum_realloc( border_changes,
border_changes_size *
sizeof( struct border_change_t )
);
}
return border_changes + border_changes_last++;
}
Expand Down
2 changes: 2 additions & 0 deletions fuse/hacking/ChangeLog
Expand Up @@ -4158,3 +4158,5 @@
GtkComboBox (patch #3531495) (Sergio).
20120605 ui/gtk/binary.c: plug a memory leak (thanks, cppcheck) (Fred).
20120607 ui/win32/binary.c: plug another memory leak (thanks, cppcheck) (Fred).
20120607 display.c,machine.c,memory.c,rectangle.c,rzx.c,tape.c,ui/widget/text.c:
switch to using libspectrum_realloc over raw realloc (Fred).
9 changes: 3 additions & 6 deletions fuse/machine.c
Expand Up @@ -113,12 +113,9 @@ static int machine_add_machine( int (*init_function)( fuse_machine_info *machine

machine_count++;

machine_types = realloc( machine_types,
machine_count * sizeof( fuse_machine_info* ) );
if( machine_types == NULL ) {
ui_error( UI_ERROR_ERROR, "out of memory at %s:%d", __FILE__, __LINE__ );
return 1;
}
machine_types =
libspectrum_realloc( machine_types,
machine_count * sizeof( fuse_machine_info* ) );

machine_types[ machine_count - 1 ] = malloc( sizeof( fuse_machine_info ) );
if( !machine_types[ machine_count - 1 ] ) {
Expand Down
8 changes: 2 additions & 6 deletions fuse/memory.c
Expand Up @@ -580,12 +580,8 @@ memory_rom_to_snapshot( libspectrum_snap *snap )
current_page_num = memory_map_rom[ i ].page_num;
} else {
/* Extend the current ROM image */
current_rom = realloc( current_rom, rom_length + MEMORY_PAGE_SIZE );
if( !current_rom ) {
ui_error( UI_ERROR_ERROR, "Out of memory at %s:%d", __FILE__,
__LINE__ );
return;
}
current_rom = libspectrum_realloc( current_rom,
rom_length + MEMORY_PAGE_SIZE );

memcpy( current_rom + rom_length, memory_map_rom[ i ].page,
MEMORY_PAGE_SIZE );
Expand Down
16 changes: 4 additions & 12 deletions fuse/rectangle.c
Expand Up @@ -70,11 +70,8 @@ rectangle_add( int y, int x, int w )
2 * rectangle_active_allocated :
8;

ptr = realloc( rectangle_active, new_alloc * sizeof( struct rectangle ) );
if( !ptr ) {
ui_error( UI_ERROR_ERROR, "Out of memory at %s:%d", __FILE__, __LINE__ );
fuse_abort();
}
ptr = libspectrum_realloc( rectangle_active,
new_alloc * sizeof( struct rectangle ) );

rectangle_active_allocated = new_alloc; rectangle_active = ptr;
}
Expand Down Expand Up @@ -171,13 +168,8 @@ rectangle_end_line( int y )
2 * rectangle_inactive_allocated :
8;

ptr = realloc( rectangle_inactive,
new_alloc * sizeof( struct rectangle ) );
if( !ptr ) {
ui_error( UI_ERROR_ERROR, "Out of memory at %s:%d",
__FILE__, __LINE__ );
fuse_abort();
}
ptr = libspectrum_realloc( rectangle_inactive,
new_alloc * sizeof( struct rectangle ) );

rectangle_inactive_allocated = new_alloc; rectangle_inactive = ptr;
}
Expand Down
6 changes: 1 addition & 5 deletions fuse/rzx.c
Expand Up @@ -573,13 +573,9 @@ int rzx_store_byte( libspectrum_byte value )

new_allocated = rzx_in_allocated >= 25 ? 2 * rzx_in_allocated : 50;
ptr =
(libspectrum_byte*)realloc(
(libspectrum_byte*)libspectrum_realloc(
rzx_in_bytes, new_allocated * sizeof(libspectrum_byte)
);
if( ptr == NULL ) {
ui_error( UI_ERROR_ERROR, "Out of memory in rzx_store_byte" );
return 1;
}

rzx_in_bytes = ptr;
rzx_in_allocated = new_allocated;
Expand Down
4 changes: 2 additions & 2 deletions fuse/tape.c
Expand Up @@ -755,8 +755,8 @@ tape_event_record_sample( libspectrum_dword last_tstates, int type,
/* make sure we can still fit a dword and a flag byte in the buffer */
if( rec_state.tape_buffer_used+5 >= rec_state.tape_buffer_size ) {
rec_state.tape_buffer_size = rec_state.tape_buffer_size*2;
rec_state.tape_buffer = realloc( rec_state.tape_buffer,
rec_state.tape_buffer_size );
rec_state.tape_buffer = libspectrum_realloc( rec_state.tape_buffer,
rec_state.tape_buffer_size );
}
}

Expand Down
7 changes: 2 additions & 5 deletions fuse/ui/widget/text.c
Expand Up @@ -163,11 +163,8 @@ widget_text_finish( widget_finish_state finished )
{
if( finished == WIDGET_FINISHED_OK ) {

widget_text_text = realloc( widget_text_text, strlen( text ) + 1 );
if( !widget_text_text ) {
ui_error( UI_ERROR_ERROR, "Out of memory at %s:%d", __FILE__, __LINE__ );
return 1;
}
widget_text_text =
libspectrum_realloc( widget_text_text, strlen( text ) + 1 );

strcpy( widget_text_text, text );
} else {
Expand Down

0 comments on commit ef2bcf5

Please sign in to comment.