From 020b295f06be92c2ced91ef9206592450632e686 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 29 Jan 2019 10:52:53 +0800 Subject: [PATCH] esp_event: fix memory leaks Closes https://github.com/espressif/esp-idf/issues/2886 --- components/esp_event/esp_event.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/esp_event/esp_event.c b/components/esp_event/esp_event.c index 8c5c0570e..149f36430 100644 --- a/components/esp_event/esp_event.c +++ b/components/esp_event/esp_event.c @@ -528,6 +528,8 @@ esp_err_t esp_event_loop_run(esp_event_loop_handle_t event_loop, TickType_t tick exec |= true; } + post_instance_delete(&post); + if (ticks_to_run != portMAX_DELAY) { end = xTaskGetTickCount(); remaining_ticks -= end - marker; @@ -559,10 +561,14 @@ esp_err_t esp_event_loop_delete(esp_event_loop_handle_t event_loop) esp_event_loop_instance_t* loop = (esp_event_loop_instance_t*) event_loop; SemaphoreHandle_t loop_mutex = loop->mutex; +#ifdef CONFIG_EVENT_LOOP_PROFILING + SemaphoreHandle_t loop_profiling_mutex = loop->profiling_mutex; +#endif xSemaphoreTakeRecursive(loop->mutex, portMAX_DELAY); #ifdef CONFIG_EVENT_LOOP_PROFILING + xSemaphoreTakeRecursive(loop->profiling_mutex, portMAX_DELAY); portENTER_CRITICAL(&s_event_loops_spinlock); SLIST_REMOVE(&s_event_loops, loop, esp_event_loop_instance, loop_entry); portEXIT_CRITICAL(&s_event_loops_spinlock); @@ -588,6 +594,10 @@ esp_err_t esp_event_loop_delete(esp_event_loop_handle_t event_loop) free(loop); // Free loop mutex before deleting xSemaphoreGiveRecursive(loop_mutex); +#ifdef CONFIG_EVENT_LOOP_PROFILING + xSemaphoreGiveRecursive(loop_profiling_mutex); + vSemaphoreDelete(loop_profiling_mutex); +#endif vSemaphoreDelete(loop_mutex); ESP_LOGD(TAG, "deleted loop %p", (void*) event_loop);