From 488a413cd2c3fb3be0a25a8dbad62fce6d2b32da Mon Sep 17 00:00:00 2001 From: Alexey Lapshin Date: Tue, 18 Jun 2024 00:17:15 +0700 Subject: [PATCH] fix(usb): fix warnings found by GNU static analyzer --- components/usb/hcd_dwc.c | 5 ++++- components/usb/usb_phy.c | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/components/usb/hcd_dwc.c b/components/usb/hcd_dwc.c index 3e5c77e8d1..dc3833cb19 100644 --- a/components/usb/hcd_dwc.c +++ b/components/usb/hcd_dwc.c @@ -1431,8 +1431,11 @@ static dma_buffer_block_t *buffer_block_alloc(usb_transfer_type_t type) break; } dma_buffer_block_t *buffer = calloc(1, sizeof(dma_buffer_block_t)); + if (buffer == NULL) { + return NULL; + } void *xfer_desc_list = heap_caps_aligned_calloc(USB_DWC_QTD_LIST_MEM_ALIGN, desc_list_len, sizeof(usb_dwc_ll_dma_qtd_t), MALLOC_CAP_DMA); - if (buffer == NULL || xfer_desc_list == NULL) { + if (xfer_desc_list == NULL) { free(buffer); heap_caps_free(xfer_desc_list); return NULL; diff --git a/components/usb/usb_phy.c b/components/usb/usb_phy.c index bd07287a3c..98aa8705c3 100644 --- a/components/usb/usb_phy.c +++ b/components/usb/usb_phy.c @@ -332,8 +332,10 @@ esp_err_t usb_new_phy(const usb_phy_config_t *config, usb_phy_handle_t *handle_r return ESP_OK; cleanup: - free(phy_context->iopins); - free(phy_context); + if (phy_context) { + free(phy_context->iopins); + free(phy_context); + } if (p_phy_ctrl_obj->ref_count == 0) { free(p_phy_ctrl_obj); p_phy_ctrl_obj = NULL;