mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-23 01:18:12 -07:00
Furi: Fix Semaphore atomicity
if thread A waiting for acquire(), thread B calls release() halfway through release() code, A would wake up and continue, before B finishes release() this could cause use-after-free if A free()s semaphore after acquire
This commit is contained in:
@@ -104,6 +104,8 @@ FuriStatus furi_semaphore_release(FuriSemaphore* instance) {
|
||||
|
||||
stat = FuriStatusOk;
|
||||
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
yield = pdFALSE;
|
||||
|
||||
@@ -123,6 +125,8 @@ FuriStatus furi_semaphore_release(FuriSemaphore* instance) {
|
||||
furi_event_loop_link_notify(&instance->event_loop_link, FuriEventLoopEventIn);
|
||||
}
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user