Explorar o código

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().
Darian Leung %!s(int64=2) %!d(string=hai) anos
pai
achega
4a15db126a
Modificáronse 1 ficheiros con 4 adicións e 7 borrados
  1. 4 7
      components/esp_ringbuf/ringbuf.c

+ 4 - 7
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)