esp-idf: esp_http_client MEMORY LEAKS (IDFGH-7651)

Environment

  • Development Kit: ESP32-Wrover-Kit
  • Kit version (for WroverKit/PicoKit/DevKitC): v3
  • Core (if using chip or module): ESP32-Wrover
  • IDF version (git rev-parse --short HEAD to get the commit id.): 4b91c82cc447640e5b61407e810f1d6f3eabd233
  • Development Env: Make
  • Operating System: Ubuntu
  • Power Supply: USB

Problem Description

esp_http_client module has memory leaks after perform. After taking a look at the code i think it is related to headers or body data. Since i was able to perform against custom server with no response packages and no leaks.

Expected Behavior

No memory leaks

Actual Behavior

TEST CASE:

Running **HTTPREQUEST - send MEMORY LEAKS ON SIMPLE PERFORM … MALLOC_CAP_8BIT potential leak: Before 227324 bytes free, After 226620 bytes free (delta 704) MALLOC_CAP_32BIT potential leak: Before 289596 bytes free, After 288892 bytes free (delta 704) ./test_httprequest.c:205:**HTTPREQUEST - send MEMORY LEAKS ON SIMPLE PERFORM :PASS Test ran in 518ms

Steps to repropduce

Just write the test below, different servers have different deltas.

Code to reproduce this issue

TEST_CASE("**HTTPREQUEST - send MEMORY LEAKS ON SIMPLE PERFORM  ", "[httprequest]")
{
    esp_http_client_config_t config = {
        .url="http://inmote.api.insite.com.co:3100/",        
    };
    esp_http_client_handle_t client = esp_http_client_init(&config);
    esp_http_client_perform(client);
    esp_http_client_cleanup(client);
}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 20 (4 by maintainers)

Most upvoted comments

Hi,

  1. I am experiencing similar issue on esp32
  2. I have enabled logs to print heap memory
  • Free HEAP : 20608

after http post

  • Free HEAP : 20384 224 bytes less

I am calling esp_http_client_cleanup(client)

it is returing ESP_OK

Here Is the code snippet I am using

_`void http_post_request(void)
{
    ESP_LOGD(TAG,"http_post_request-start -----> heap_caps_check_integrity_all : %s ", heap_caps_check_integrity_all(true) ? "true" : "false"); 
    ESP_LOGD(TAG,"http_post_request-start -----> free DRAM %u IRAM %u",heap_caps_get_free_size(MALLOC_CAP_8BIT),heap_caps_get_free_size(MALLOC_CAP_32BIT));
    esp_http_client_config_t config = 
    {
    .url = SomePath,
    .event_handler = _http_event_handler,
    };
    esp_http_client_handle_t client = esp_http_client_init(&config);
    if(client == NULL)
    {
       ESP_LOGE(TAG, "POST fail");
       Err_Flag = eADM_HTTP_FAIL;
    }
    else
    {
        const char *post_data = string;
        esp_http_client_set_url(client, somePath);
        esp_http_client_set_method(client, HTTP_METHOD_POST);
        esp_http_client_set_post_field(client, post_data, strlen(post_data));
        esp_err_t err = esp_http_client_perform(client);
        if (err == ESP_OK) {
            ESP_LOGD(TAG, "HTTP POST Status = %d",
                    esp_http_client_get_status_code(client));
        } 
        else 
        {
            ESP_LOGE(TAG, "POST fail: %s", esp_err_to_name(err));
            Err_Flag = eADM_HTTP_FAIL;
        }

        if(esp_http_client_cleanup(client)==ESP_OK)
            ESP_LOGI(TAG,"http connection closed clean");
        else
            ESP_LOGI(TAG,"http connection closed unclean");

ESP_LOGD(TAG,"http_post_request-start -----> heap_caps_check_integrity_all : %s ", heap_caps_check_integrity_all(true) ? "true" : "false"); 
ESP_LOGD(TAG,"http_post_request-start -----> free DRAM %u IRAM %u",heap_caps_get_free_size(MALLOC_CAP_8BIT),heap_caps_get_free_size(MALLOC_CAP_32BIT));
  
    }
}`_