DaveGamble / cJSON

Ultralightweight JSON parser in ANSI C
MIT License
10.28k stars 3.15k forks source link

Memory Leak in the cJSON_Free #861

Closed Petreon closed 1 month ago

Petreon commented 1 month ago

when you use the cJSON_free() in the structure it doesnt free the obj->string that is previously allocated in the contruction of the tree, we need to deallocated the string manually, i only found this when i need to parse a 500k json lines, and the memory lost in the heap was almost 100x the size of the real object

PeterAlfredLee commented 1 month ago

The cJSON_free is only a wrapper of global_hooks.deallocate. If you want to free a cjson item, use cJSON_Delete instead.

Petreon commented 1 month ago

Thanks, for the fast response, it worked here !