From 547c16ac548e8e813b6e3812af6a996207d9683b Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Thu, 21 Nov 2024 10:38:53 +0100 Subject: [PATCH] Fixing memory leak --- src/main.cpp | 14 -------------- src/stock.cpp | 3 +++ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c32c1a1..a741521 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,10 +5,6 @@ #include "stock.h" #include "wifi.h" -//#include "esp_heap_trace.h" - -//static heap_trace_record_t trace_record[200]; - esp_err_t init_nvs() { esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { @@ -28,7 +24,6 @@ void init() { extern "C" void app_main() { // TODO: Get internet with GUEST_WLAN - // TODO: Memory leak const char* TAG = "app_main"; @@ -42,18 +37,9 @@ extern "C" void app_main() { xTaskCreate(fetch_stock_task, "fetch_stock_task", 1024*4, NULL, configMAX_PRIORITIES-1, NULL); /* - ESP_ERROR_CHECK(heap_trace_init_standalone(trace_record, 200)); - ESP_ERROR_CHECK(heap_trace_start(HEAP_TRACE_LEAKS)); - - int i = 1; for(;;) { ESP_LOGI("mem", "Free heap=%lu", esp_get_free_heap_size()); vTaskDelay(60000 / portTICK_PERIOD_MS); - if(--i == 0) { - ESP_ERROR_CHECK(heap_trace_stop()); - heap_trace_dump(); - } - } */ diff --git a/src/stock.cpp b/src/stock.cpp index c757024..547d120 100644 --- a/src/stock.cpp +++ b/src/stock.cpp @@ -84,15 +84,18 @@ esp_err_t parse_JSON(const char* json, float* current, float* delta) { if (cJSON_GetObjectItem(root, "c")) { *current = (float)cJSON_GetObjectItem(root,"c")->valuedouble; } else { + cJSON_Delete(root); return ESP_ERR_NOT_FOUND; } if (cJSON_GetObjectItem(root, "d")) { *delta = (float)cJSON_GetObjectItem(root,"d")->valuedouble; } else { + cJSON_Delete(root); return ESP_ERR_NOT_FOUND; } + cJSON_Delete(root); return ESP_OK; } -- libgit2 0.22.2