使用JSON-C的内存泄漏 [英] Memory Leak Using JSON-C
本文介绍了使用JSON-C的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是JSON-C的新手,请查看我的示例代码,让我知道它会造成任何内存泄漏,如果可以,那么如何释放JSON-C对象.
I am new to JSON-C, Please see my sample code and let me know of it will create any memory leak, if yes then how to free JSON-C object.
struct json_object *new_obj = NULL;
new_obj = json_tokener_parse(strRawJSON);
new_obj = json_object_object_get(new_obj, "FUU");
if(NULL == new_obj){
SYS_OUT("\nFUU not found in JSON");
return NO;
}
new_obj = json_object_object_get(new_obj, "FOO"); // I m re-using new_obj, without free it?
if(NULL == new_obj){
SYS_OUT("\nFOO not found in JSON");
return NO;
}
// DO I need to clean new_obj, if yes then how ??
我是否需要清洁new_obj,如果是,那么如何清洁.有人可以帮助您了解如何进行JSON-C内存管理.
Do I need to clean new_obj, if yes then how. Can some one help to understand how to do memory management JSON-C.
预先感谢
推荐答案
否,只要我们不为json-object显式分配内存,我们就只需要为根对象调用一次json_object_put,这对我有用. .. !!
NO, We need to call json_object_put only once for root object as long as we are not explicitly allocating memory to json-object and this worked for me.....!!
这篇关于使用JSON-C的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文