esp32-tutorial
esp32-tutorial copied to clipboard
Tutorial 30: Memory leak after parsing JSON file
Hi Luca,
You have a memory leak here:
cJSON *json = cJSON_Parse(rcv_buffer);
You need to call the following line to free it:
cJSON_Delete(json);
Reference document for the cJSON library is here: https://github.com/DaveGamble/cJSON
Given some JSON in a zero terminated string, you can parse it with cJSON_Parse.
cJSON *json = cJSON_Parse(string);
It will parse the JSON and allocate a tree of cJSON items that represents it. Once it returns, you are fully responsible for deallocating it after use with cJSON_Delete.