This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Possible memory leak

Hi all,

I am testing an application that we collect wifi information from ESP32, then encode in JSON format, then send to cloud server in the 1 minute-interval.

However, after about 30 minutes, we received an error from cJSON APIs, then I can not do the encoding anymore.

I did some debugging, the program always stopped at some cJSON APIs related to create cJSON object (number or string) after running about 30 minutes.

At first, I did not think it is the memory leak issue, because in each encoding task, I always use these two below functions to free the memory.

cJSON_PrintPreallocated()

cJSON_Delete()

As I know, the cJSON_Delete is using the k_free() function to free memory, I did an experiment with k_free(), and I see that k_free() did not work as expected.

It could not free memory allocated by k_malloc()

My environment is NRF9160 and SDK ver 1.3

Could you help me to overcome this issue ?

Parents
  • If you could upload a simplified project I can run to reproduce the problem, that would be helpful.

    However, I found a comment here that may point to the cause of the failure:

    "Anyway it's most likely you're creating a JSON object (somewhere) and forgetting to add it to the root object or any of its descendants. When the root object is deleted the un-connected elements are not deleted and leaks memory."

    Best regards,

    Simon

Reply
  • If you could upload a simplified project I can run to reproduce the problem, that would be helpful.

    However, I found a comment here that may point to the cause of the failure:

    "Anyway it's most likely you're creating a JSON object (somewhere) and forgetting to add it to the root object or any of its descendants. When the root object is deleted the un-connected elements are not deleted and leaks memory."

    Best regards,

    Simon

Children
Related