JSON-C中的内存泄漏

时间:2016-05-20 05:16:44

标签: c++ c json memory-leaks

我搜索了两天,但发现我的内存泄漏了。我尝试了很多想法,但现在我可以确认泄漏是在我使用json-c lib的cpp文件中。 这是一个例子:

#define mark_one 6
#define mark_two 18
#define mark_three 36

json_object * json_devicedata() {

json_object *jobj_device_data = json_object_new_object();
json_object *jobj_array_typen = json_object_new_array();
json_object *jobj_array_werte = json_object_new_array();

json_object_array_add(jobj_array_typen, json_object_new_int(101)); //Key
json_object_array_add(jobj_array_werte, json_object_new_int(2));

json_object_array_add(jobj_array_typen, json_object_new_int(102)); //Timestamp
json_object_array_add(jobj_array_werte, json_object_new_int(TIMER->run_can));

json_object_array_add(jobj_array_typen, json_object_new_int(103)); 

json_object_array_add(jobj_array_typen, json_object_new_int(994));

json_object_object_add(jobj_device_data, "type", jobj_array_typen);
json_object_object_add(jobj_device_data, "value", jobj_array_werte);

return jobj_device_data;
}

void json_writer(MyClass *Test, struct Filework *DATEI) {
json_object *tiny = json_object_new_object();
json_object *result = json_object_new_object();

json_object *minimalistic = json_object_new_array();

json_object *shorty;
for (unsigned short counterStrang = 0; counterStrang < mark_one; counterStrang++) {
    for (unsigned short counterModul = 0; counterModul < mark_two; counterModul++) {
        for (unsigned short counterZelle = 0; counterZelle < mark_three; counterZelle++) {
            shorty = json_devicedata();
                                json_object_array_add(minimalistic, shorty);
        }
    }
}

json_object_object_add(tiny, "value", minimalistic);

json_object *mini = json_object_new_array();
json_object_array_add(mini, tiny);
json_object_object_add(result, "value", mini);

fprintf(DATEI->output_json, "%s", json_object_to_json_string(result));
fprintf(DATEI->output_json, ",");

json_object_put(result);
delete Test;
}

我试图用&#34; json_object_put(结果)&#34;释放内存。但它dosnet似乎释放了一切。有人可以帮忙吗?

谢谢!

0 个答案:

没有答案