From 18164e6f021f12bb9bee4a0ce772ea64b36d2f8f Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 29 Jun 2023 17:13:05 -0300 Subject: [PATCH] Fixes crash when calling twice end() (#8332) --- cores/esp32/HWCDC.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/cores/esp32/HWCDC.cpp b/cores/esp32/HWCDC.cpp index 6ec8625cff9..cc0202f657c 100644 --- a/cores/esp32/HWCDC.cpp +++ b/cores/esp32/HWCDC.cpp @@ -218,10 +218,10 @@ void HWCDC::setTxTimeoutMs(uint32_t timeout){ size_t HWCDC::setTxBufferSize(size_t tx_queue_len){ if(tx_ring_buf){ - if(!tx_queue_len){ - vRingbufferDelete(tx_ring_buf); - tx_ring_buf = NULL; - } + vRingbufferDelete(tx_ring_buf); + tx_ring_buf = NULL; + } + if(!tx_queue_len){ return 0; } tx_ring_buf = xRingbufferCreate(tx_queue_len, RINGBUF_TYPE_BYTEBUF); @@ -319,19 +319,16 @@ void HWCDC::flush(void) size_t HWCDC::setRxBufferSize(size_t rx_queue_len){ if(rx_queue){ - if(!rx_queue_len){ - vQueueDelete(rx_queue); - rx_queue = NULL; - } + vQueueDelete(rx_queue); + rx_queue = NULL; + } + if(!rx_queue_len){ return 0; } rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); if(!rx_queue){ return 0; } - if(!tx_ring_buf){ - tx_ring_buf = xRingbufferCreate(rx_queue_len, RINGBUF_TYPE_BYTEBUF); - } return rx_queue_len; }