cemu-project / Cemu

Cemu - Wii U emulator
https://cemu.info
Mozilla Public License 2.0
6.65k stars 518 forks source link

coreinit: fix race condition that causes crash #1138

Closed goeiecool9999 closed 3 months ago

goeiecool9999 commented 3 months ago

On linux cemu sometimes randomly crashes on startup. Looking at the coredump in a debugger showed that it crashed in emplace_back for a vector because of a double free. Write access to a vector is not thread-safe, but when cemu is in multi-core recompiler mode when the timing is just right two or more threads simultaneously emplace in the vector. Added a mutex to protect access.

Exzap commented 3 months ago

The timing on this race condition is extremely narrow, so it's interesting that you got it to trigger. Thanks for the fix