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>
This commit is contained in:
		
							parent
							
								
									9a21dae29c
								
							
						
					
					
						commit
						e42dda7cfb
					
				| @ -215,26 +215,26 @@ static UartEchoApp* uart_echo_app_alloc() { | |||||||
|     view_dispatcher_add_view(app->view_dispatcher, 0, app->view); |     view_dispatcher_add_view(app->view_dispatcher, 0, app->view); | ||||||
|     view_dispatcher_switch_to_view(app->view_dispatcher, 0); |     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
 |     // Enable uart listener
 | ||||||
|     furi_hal_console_disable(); |     furi_hal_console_disable(); | ||||||
|     furi_hal_uart_set_br(FuriHalUartIdUSART1, 115200); |     furi_hal_uart_set_br(FuriHalUartIdUSART1, 115200); | ||||||
|     furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, uart_echo_on_irq_cb, app); |     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; |     return app; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void uart_echo_app_free(UartEchoApp* app) { | static void uart_echo_app_free(UartEchoApp* app) { | ||||||
|     furi_assert(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_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventStop); | ||||||
|     furi_thread_join(app->worker_thread); |     furi_thread_join(app->worker_thread); | ||||||
|     furi_thread_free(app->worker_thread); |     furi_thread_free(app->worker_thread); | ||||||
| 
 | 
 | ||||||
|     furi_hal_console_enable(); |  | ||||||
| 
 |  | ||||||
|     // Free views
 |     // Free views
 | ||||||
|     view_dispatcher_remove_view(app->view_dispatcher, 0); |     view_dispatcher_remove_view(app->view_dispatcher, 0); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 0xchocolate
						0xchocolate