When I run my program , it calls a function that have a "char *msgtype" and this function work probably but when another function use a different "char *msgtype" in it when program reach the line that contain it , program crashes(and even when the firs function is called for second time program crashes). What is the problem ?
and if I change the name in the second function it just work one time and after calling that function again program crashes !
void fun1(){
...
cJSON *root = cJSON_Parse(buffer);
char *msgtype = cJSON_GetObjectItem(root,"type")->valuestring;
...
free(msgtype);
cJSON_Delete(root);
...
}
void fun2(){
...
cJSON *root = cJSON_Parse(buffer);
char *msgtype = cJSON_GetObjectItem(root,"type")->valuestring;//it crashes here
...
free(msgtype);
cJSON_Delete(root);
...
}
int main(){
fun1();
fun2();//it crashes inside this function !
}