Commit 547c16ac548e8e813b6e3812af6a996207d9683b

Authored by Imanol-Mikel Barba Sabariego
1 parent ab99f821

Fixing memory leak

Showing 2 changed files with 3 additions and 14 deletions
src/main.cpp
... ... @@ -5,10 +5,6 @@
5 5 #include "stock.h"
6 6 #include "wifi.h"
7 7  
8   -//#include "esp_heap_trace.h"
9   -
10   -//static heap_trace_record_t trace_record[200];
11   -
12 8 esp_err_t init_nvs() {
13 9 esp_err_t ret = nvs_flash_init();
14 10 if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
... ... @@ -28,7 +24,6 @@ void init() {
28 24  
29 25 extern "C" void app_main() {
30 26 // TODO: Get internet with GUEST_WLAN
31   - // TODO: Memory leak
32 27  
33 28 const char* TAG = "app_main";
34 29  
... ... @@ -42,18 +37,9 @@ extern "C" void app_main() {
42 37 xTaskCreate(fetch_stock_task, "fetch_stock_task", 1024*4, NULL, configMAX_PRIORITIES-1, NULL);
43 38  
44 39 /*
45   - ESP_ERROR_CHECK(heap_trace_init_standalone(trace_record, 200));
46   - ESP_ERROR_CHECK(heap_trace_start(HEAP_TRACE_LEAKS));
47   -
48   - int i = 1;
49 40 for(;;) {
50 41 ESP_LOGI("mem", "Free heap=%lu", esp_get_free_heap_size());
51 42 vTaskDelay(60000 / portTICK_PERIOD_MS);
52   - if(--i == 0) {
53   - ESP_ERROR_CHECK(heap_trace_stop());
54   - heap_trace_dump();
55   - }
56   -
57 43 }
58 44 */
59 45  
... ...
src/stock.cpp
... ... @@ -84,15 +84,18 @@ esp_err_t parse_JSON(const char* json, float* current, float* delta) {
84 84 if (cJSON_GetObjectItem(root, "c")) {
85 85 *current = (float)cJSON_GetObjectItem(root,"c")->valuedouble;
86 86 } else {
  87 + cJSON_Delete(root);
87 88 return ESP_ERR_NOT_FOUND;
88 89 }
89 90  
90 91 if (cJSON_GetObjectItem(root, "d")) {
91 92 *delta = (float)cJSON_GetObjectItem(root,"d")->valuedouble;
92 93 } else {
  94 + cJSON_Delete(root);
93 95 return ESP_ERR_NOT_FOUND;
94 96 }
95 97  
  98 + cJSON_Delete(root);
96 99 return ESP_OK;
97 100 }
98 101  
... ...