esp32-tutorial icon indicating copy to clipboard operation
esp32-tutorial copied to clipboard

Tutorial 30: Memory leak after parsing JSON file

Open asweeney99 opened this issue 5 years ago • 0 comments

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.

asweeney99 avatar Apr 18 '19 13:04 asweeney99