cJSON memory leak is a post where a memory leak occured. But the problem n this case is the cJSON_Print() function.
I did not even use this function (have commented it for the time being) and have still a memory leakage. My ode looks like this
void myFunc(cJSON* ptr)
{
/*some code */
// I have used some sint32 numbers from another library for simplicity
// i will use int
int num = 30
cJSON_AddItemToArray(pt_data,cJSON_CreateNumber(num));
}
int main()
{
cJSON *root =cJSON_CreateObject();
cJSON *pt_PPC= cJSON_CreateArray();
cJSON_AddItemToObject(root,"PowerPC",pt_PPC);
cJSON *pt_data = cJSON_CreateArray();
cJSON_AddItemToArray(pt_PPC,pt_data);
int i;
for(i=0;i<10;i++)
myFunc(pt_PPC);
cJSON_Delete(root);
return 0;
}
The memory increases with time. Any suggestions?