Procházet zdrojové kódy

Merge branch 'bugfix/malloc_warnings_rtc' into 'master'

rtc: fix minor malloc issues found by static analyzer

See merge request espressif/esp-idf!5144
Angus Gratton před 6 roky
rodič
revize
c4e5c62cda
1 změnil soubory, kde provedl 9 přidání a 4 odebrání
  1. 9 4
      components/driver/rtc_module.c

+ 9 - 4
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(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);
     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);
     xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
     if (s_touch_pad_filter == NULL) {
     if (s_touch_pad_filter == NULL) {
         s_touch_pad_filter = (touch_pad_filter_t *) calloc(1, sizeof(touch_pad_filter_t));
         s_touch_pad_filter = (touch_pad_filter_t *) calloc(1, sizeof(touch_pad_filter_t));
         if (s_touch_pad_filter == NULL) {
         if (s_touch_pad_filter == NULL) {
-            ret = ESP_ERR_NO_MEM;
+            goto err_no_mem;
         }
         }
     }
     }
     if (s_touch_pad_filter->timer == NULL) {
     if (s_touch_pad_filter->timer == NULL) {
         s_touch_pad_filter->timer = xTimerCreate("filter_tmr", filter_period_ms / portTICK_PERIOD_MS, pdFALSE,
         s_touch_pad_filter->timer = xTimerCreate("filter_tmr", filter_period_ms / portTICK_PERIOD_MS, pdFALSE,
         NULL, touch_pad_filter_cb);
         NULL, touch_pad_filter_cb);
         if (s_touch_pad_filter->timer == NULL) {
         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;
         s_touch_pad_filter->period = filter_period_ms;
     }
     }
     xSemaphoreGive(rtc_touch_mux);
     xSemaphoreGive(rtc_touch_mux);
     touch_pad_filter_cb(NULL);
     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()
 esp_err_t touch_pad_filter_stop()