Skip to content

Commit c443868

Browse files
authored
fix: crashing end()
Fixes a crash when calling end() end() treminanates the `tx_ring_buf` but it was not tested for NULL in the ISR and in the cdc0_write_char() causing a crash if those are used. This depends on events and happens eventually.
1 parent d216665 commit c443868

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cores/esp32/HWCDC.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void hw_cdc_isr_handler(void *arg) {
8787
} else {
8888
connected = true;
8989
}
90-
if (usb_serial_jtag_ll_txfifo_writable() == 1) {
90+
if (tx_ring_buf != NULL && usb_serial_jtag_ll_txfifo_writable() == 1) {
9191
// We disable the interrupt here so that the interrupt won't be triggered if there is no data to send.
9292
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
9393
size_t queued_size;
@@ -165,6 +165,9 @@ bool HWCDC::isCDC_Connected()
165165
}
166166

167167
static void ARDUINO_ISR_ATTR cdc0_write_char(char c) {
168+
if(tx_ring_buf == NULL) {
169+
return;
170+
}
168171
uint32_t tx_timeout_ms = 0;
169172
if(HWCDC::isConnected()) {
170173
tx_timeout_ms = requested_tx_timeout_ms;
@@ -292,6 +295,7 @@ void HWCDC::end()
292295
arduino_hw_cdc_event_loop_handle = NULL;
293296
}
294297
HWCDC::deinit(this);
298+
setDebugOutput(false);
295299
connected = false;
296300
}
297301

0 commit comments

Comments
 (0)