From 4a15db126ae656eb0c592d623b2840c0983f5697 Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Fri, 30 Jun 2023 14:22:43 +0100 Subject: [PATCH] fix(esp_ringbuf): Fix "USE_AFTER_FREE" coverity issue Fix false positive in coverity where it thinks memory buffers are freed for statically created ring buffers, leading to a "USE_AFTER_FREE" warning in vRingbufferDeleteWithCaps(). --- components/esp_ringbuf/ringbuf.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/components/esp_ringbuf/ringbuf.c b/components/esp_ringbuf/ringbuf.c index 1457db4d34..a5222cf603 100644 --- a/components/esp_ringbuf/ringbuf.c +++ b/components/esp_ringbuf/ringbuf.c @@ -1244,14 +1244,11 @@ void vRingbufferDelete(RingbufHandle_t xRingbuffer) Ringbuffer_t *pxRingbuffer = (Ringbuffer_t *)xRingbuffer; configASSERT(pxRingbuffer); -#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) - if (pxRingbuffer->uxRingbufferFlags & rbBUFFER_STATIC_FLAG) { - //Ring buffer was statically allocated, no need to free - return; + //Ring buffer was not statically allocated. Free its memory. + if ( !( pxRingbuffer->uxRingbufferFlags & rbBUFFER_STATIC_FLAG ) ) { + free(pxRingbuffer->pucHead); + free(pxRingbuffer); } -#endif - free(pxRingbuffer->pucHead); - free(pxRingbuffer); } size_t xRingbufferGetMaxItemSize(RingbufHandle_t xRingbuffer)