Przeglądaj źródła

UART echo: fix race conditions causing null pointer dereference (#2092)

Co-authored-by: 0xchocolate <0xchocolate@users.noreply.github.com>
Co-authored-by: あく <alleteam@gmail.com>
0xchocolate 3 lat temu
rodzic
commit
e42dda7cfb
1 zmienionych plików z 5 dodań i 5 usunięć
  1. 5 5
      applications/debug/uart_echo/uart_echo.c

+ 5 - 5
applications/debug/uart_echo/uart_echo.c

@@ -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);