mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
c1d5717013
The crash occurred when calling setvbuf(stdin,...) with stdin==NULL. This happened because esp_console_repl_task started running before its args->uart_channel was initialized; then esp_console_repl_task went into the code path 'uart_channel != CONFIG_ESP_CONSOLE_UART_NUM', and tried to 'fopen("/dev/uart/0");` Since the UART VFS is not registered when ESP_CONSOLE_USB_SERIAL_JTAG option is enabled, fopen failed and 'stdin' was NULL. Fix by moving the initialization of repl task arguments before the start of the task, same as it is done for the usb_cdcacm case. The crash started happening after the commit 287ab7566b9. I haven’t verified this, but I guess the reason why it wasn’t happening before was that xTaskCreate was not correctly yielding to the newly created higher-priority 'repl' task, therefore the code which was setting the repl task arguments after xTaskCreate had time to execute. It should be noted that the 'uart_channel' argument is a bit hacky, in the first place. The code should be refactored to pass a callback function to the repl task, and let this callback initialize stdin and stdout based on the chosen console channel. Then esp_console_repl_task does not require assumptions about the specific interface used. Closes https://github.com/espressif/esp-idf/issues/9662