Skip to content
Permalink
Browse files

Bug fix: avoid circular list destroying by memory overwrite.

Recreate rewind list after each rom loading, to ensure that
proper state size is used.
  • Loading branch information...
Maciek
Maciek committed Jun 27, 2018
1 parent 2a77483 commit f24f716069534fe42c3474535c5b5cce67d70c62
Showing with 16 additions and 11 deletions.
  1. +3 −0 gbcore/gb.c
  2. +1 −1 main.c
  3. +12 −10 rewind.c
@@ -22,6 +22,7 @@

#include "gb.h"
#include "../menu.h"
#include "../rewind.h"

#define VFRAME_SIZE (SIZE_LINE*256*2)

@@ -139,6 +140,8 @@ bool gb_load_rom(byte *buf,int size,byte *ram,int ram_size)
{
if (rom_load_rom(buf,size,ram,ram_size)){
gb_reset();
free_rewind_states();
allocate_rewind_states();
return true;
}
else
2 main.c
@@ -146,7 +146,7 @@ void mainloop(void)
int line, turbo_bak=0;

ctrl_data_t paddata;// davex: for rewind checking
allocate_rewind_states();
// allocate_rewind_states();
save_period_frames = 10;

for(;;) {
@@ -60,16 +60,18 @@ void free_rewind_states(void){
struct rewind_state *now_state;

now_state = ptr_rewind_states;
prev_state = now_state->prev;
prev_state->next = NULL;

while(1){
if ( now_state == NULL)
break;
next_state = now_state->next;
free(now_state->data );
free(now_state);
now_state = next_state;
if(ptr_rewind_states){
prev_state = now_state->prev;
prev_state->next = NULL;

while(1){
if ( now_state == NULL)
break;
next_state = now_state->next;
free(now_state->data );
free(now_state);
now_state = next_state;
}
}
}

0 comments on commit f24f716

Please sign in to comment.
You can’t perform that action at this time.