From c6c6cd71796105724c8a632fe51f1d6bc58debd3 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 31 May 2019 15:36:00 +0200 Subject: [PATCH] rtc: fix minor malloc issues found by static analyzer --- components/driver/rtc_module.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/components/driver/rtc_module.c b/components/driver/rtc_module.c index eae287199..1be5c645c 100644 --- a/components/driver/rtc_module.c +++ b/components/driver/rtc_module.c @@ -980,25 +980,30 @@ esp_err_t touch_pad_filter_start(uint32_t filter_period_ms) RTC_MODULE_CHECK(filter_period_ms >= portTICK_PERIOD_MS, "Touch pad filter period error", ESP_ERR_INVALID_ARG); RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE); - esp_err_t ret = ESP_OK; xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); if (s_touch_pad_filter == NULL) { s_touch_pad_filter = (touch_pad_filter_t *) calloc(1, sizeof(touch_pad_filter_t)); if (s_touch_pad_filter == NULL) { - ret = ESP_ERR_NO_MEM; + goto err_no_mem; } } if (s_touch_pad_filter->timer == NULL) { s_touch_pad_filter->timer = xTimerCreate("filter_tmr", filter_period_ms / portTICK_PERIOD_MS, pdFALSE, NULL, touch_pad_filter_cb); if (s_touch_pad_filter->timer == NULL) { - ret = ESP_ERR_NO_MEM; + free(s_touch_pad_filter); + s_touch_pad_filter = NULL; + goto err_no_mem; } s_touch_pad_filter->period = filter_period_ms; } xSemaphoreGive(rtc_touch_mux); touch_pad_filter_cb(NULL); - return ret; + return ESP_OK; + +err_no_mem: + xSemaphoreGive(rtc_touch_mux); + return ESP_ERR_NO_MEM; } esp_err_t touch_pad_filter_stop()