This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHCC3235MOD: Heap memory overflow of in HTTPClient library while making consecutive request

Part Number: LAUNCHCC3235MOD

Hi,

I have executed 20 HTTP POST continuously by modifying the httpget example code provided by SDK version 6.10.

for(i =0; i <20; i++)
{

UART_PRINT("\n\r\n\r******Executing %d ********\n\r\n\r", i);

httpPost();
sleep(2);
}

Below is the sequence of the httppost function. It is working fine for the first 16 requests, but it fails to make a connection after that because of the heap memory overflow.

HTTPClient_create

HTTPClient_setHeader

HTTPClient_connect

HTTPClient_sendRequest

HTTPClient_readResponseBody

HTTPClient_disconnect

HTTPClient_destroy

Below is the increment I have seen from ROV. Heap memory usage increases each request.

Please help me to fix this issue.

Regards,

Sundar

  • I've just verified there is no memory leak when using the reference httpGet example.

    If you are based on this example, you should verify your changes.

    Are you allocating data inside the httpPost() ?

  • Hi Kobi,

    Thank you for checking. I also eliminated JSON-related code and tested again.

    The HTTP client code works fine. When I add the below code inside the function, it throws an error while making an HTTP connection.

    char jtemplate [] =
    "{\"Sec\": string,\"Minute\": string,\"Hour\": string,"
    "\"Day\": string,\"Month\": string,\"Year\": string, \"Bitrate\": string,\"IfUppgrade\": string,\"IfAlarm\": string,\"Info\": string}";

    ret = Json_init(jtemplate,data, strlen(data));
    if(ret < 0)
    {
    LOG_MESSAGE("Json_init failed", ret);
    }

    Please help me to resolve this issue.

    Regards,

    Sundar

  • Hi Kobi,

    Here is the Json_init function.

    int16_t Json_init(char *template,
    char *text,
    uint16_t textLen)
    {
    int16_t retVal;

    retVal = Json_createTemplate(&HttpJsonObj.templateHandle, template,
    strlen(template));

    if(retVal < 0)
    {
    LOG_MESSAGE("Error: %d , Couldn't create template \r\n",retVal);
    return(-1);
    }

    retVal =
    Json_createObject(&HttpJsonObj.jsonObjHandle,HttpJsonObj.templateHandle,
    1024);
    if(retVal < 0)
    {
    /* Failed to create an object, free the allocated template */
    Json_destroyTemplate(HttpJsonObj.templateHandle);
    LOG_MESSAGE("Error: %d , Couldn't create Json object \r\n",retVal);
    return(-1);
    }

    //LOG_MESSAGE("response:%s_1 \r\n", text);

    retVal = Json_parse(HttpJsonObj.jsonObjHandle, text,textLen);

    if(retVal < 0)
    {
    LOG_MESSAGE("Error: %d , Couldn't parse"
    " the received Json file \r\n",
    retVal);

    /* Failed to parse the JSON file, free the allocated memory */
    Json_destroy();

    return(retVal);
    }

    return(0);
    }

    Regards,

    Sundar

  • Hi Kobi,

    Thanks for your help. I miss the Json_destroy function at the end.

    Regards,

    Sundar