exit()/atexit() is replaced with setjmp()/longjmp() combo to allow graceful shutdown with cleanup handler. In a nutshell, exit() is replaced with main_exit() which performs longjmp. So now Nofrendo can be exited with event_quit.
In nes/nes_rom.c, memory for rom and vrom was allocated WITHOUT using guards (mem_alloc) but freed WITH using guards (NOFRENDO_FREE). This caused the "mem_deleteblock ... -- block not found" which called exit() and thus crashed the app. This is now fixed.
Memory corruption in bitmap.c is still present, however it doesn't seem to cause any issues. So I replaced ASSERT_MSG with a log message to treat corrupted memory blocks as non-critical issue and proceed with a normal shutdown.
All changes tested on actual hardware: I was able to successfully exit the emulator back into my main firmware with no memory leaks.
This PR introduces several improvements:
exit()
/atexit()
is replaced withsetjmp()
/longjmp()
combo to allow graceful shutdown with cleanup handler. In a nutshell,exit()
is replaced withmain_exit()
which performslongjmp
. So now Nofrendo can be exited withevent_quit
.nes/nes_rom.c
, memory forrom
andvrom
was allocated WITHOUT using guards (mem_alloc
) but freed WITH using guards (NOFRENDO_FREE
). This caused the "mem_deleteblock ... -- block not found" which calledexit()
and thus crashed the app. This is now fixed.bitmap.c
is still present, however it doesn't seem to cause any issues. So I replacedASSERT_MSG
with a log message to treat corrupted memory blocks as non-critical issue and proceed with a normal shutdown.All changes tested on actual hardware: I was able to successfully exit the emulator back into my main firmware with no memory leaks.