Skip to content

Commit

Permalink
UART echo: fix race conditions causing null pointer dereference (#2092)
Browse files Browse the repository at this point in the history
Co-authored-by: 0xchocolate <[email protected]>
Co-authored-by: あく <[email protected]>
  • Loading branch information
3 people authored Dec 7, 2022
1 parent 9a21dae commit e42dda7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions applications/debug/uart_echo/uart_echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,26 +215,26 @@ static UartEchoApp* uart_echo_app_alloc() {
view_dispatcher_add_view(app->view_dispatcher, 0, app->view);
view_dispatcher_switch_to_view(app->view_dispatcher, 0);

app->worker_thread = furi_thread_alloc_ex("UsbUartWorker", 1024, uart_echo_worker, app);
furi_thread_start(app->worker_thread);

// Enable uart listener
furi_hal_console_disable();
furi_hal_uart_set_br(FuriHalUartIdUSART1, 115200);
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, uart_echo_on_irq_cb, app);

app->worker_thread = furi_thread_alloc_ex("UsbUartWorker", 1024, uart_echo_worker, app);
furi_thread_start(app->worker_thread);

return app;
}

static void uart_echo_app_free(UartEchoApp* app) {
furi_assert(app);

furi_hal_console_enable(); // this will also clear IRQ callback so thread is no longer referenced

furi_thread_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventStop);
furi_thread_join(app->worker_thread);
furi_thread_free(app->worker_thread);

furi_hal_console_enable();

// Free views
view_dispatcher_remove_view(app->view_dispatcher, 0);

Expand Down

0 comments on commit e42dda7

Please sign in to comment.