Commit 3eedad0
committed
runloop_event_deinit_core calls retro_unload_game and retro_deinit
before uninit_libretro_symbols. The autosave_t->retro_buffer field
borrows a pointer from core_get_memory(), and the autosave worker
thread reads from it continuously via memcpy and intfstream_write.
If a worker is mid-read when retro_unload_game / retro_deinit frees
the underlying memory, the worker reads freed memory.
The standard MAIN_DEINIT path joins the autosave worker at
retroarch.c:8508 (autosave_deinit, gated on RUNLOOP_FLAG_USE_SRAM)
before reaching CMD_EVENT_CORE_DEINIT at line 8524. That path is
safe.
The error paths in retroarch_main_init are not safe. The dummy-core
fallback at retroarch.c:8314 and the error: label at retroarch.c:8414
both call CMD_EVENT_CORE_DEINIT directly without first joining the
autosave worker. event_init_content (the function whose failure
typically lands us in those error paths) calls
runloop_path_init_savefile -> CMD_EVENT_AUTOSAVE_INIT, which can
start a worker thread before later steps in event_init_content fail.
That worker is still running when CMD_EVENT_CORE_DEINIT executes.
Make runloop_event_deinit_core join the autosave worker itself,
gated on RUNLOOP_FLAG_USE_SRAM to match the existing MAIN_DEINIT
gate. autosave_deinit is idempotent (loop is empty when
autosave_state.num is 0, free(NULL) is a no-op), so this is safe
to call from the standard path where the worker was already joined.
This makes the retro_buffer borrow lifetime contract local to
runloop_event_deinit_core rather than depending on call-site
discipline at every CMD_EVENT_CORE_DEINIT site.1 parent 7c4b483 commit 3eedad0
1 file changed
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4063 | 4063 | | |
4064 | 4064 | | |
4065 | 4065 | | |
| 4066 | + | |
| 4067 | + | |
| 4068 | + | |
| 4069 | + | |
| 4070 | + | |
| 4071 | + | |
| 4072 | + | |
| 4073 | + | |
| 4074 | + | |
| 4075 | + | |
| 4076 | + | |
| 4077 | + | |
| 4078 | + | |
| 4079 | + | |
| 4080 | + | |
| 4081 | + | |
| 4082 | + | |
| 4083 | + | |
| 4084 | + | |
4066 | 4085 | | |
4067 | 4086 | | |
4068 | 4087 | | |
| |||
0 commit comments