c - 使用 JSON-C 的内存泄漏

标签 c json memory-management memory-leaks json-c

我是 JSON-C 的新手,请查看我的示例代码,让我知道它会造成任何内存泄漏,如果是,那么如何释放 JSON-C 对象。

    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。

提前致谢

最佳答案

不,我们只需要为根对象调用 json_object_put 一次,只要我们没有显式地将内存分配给 json-object 并且这对我有用......!!

关于c - 使用 JSON-C 的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8746155/

相关文章:

c++ - 释放分配给存储在 vector 中的堆的内存

Java vector : how to quickly "symmetrify" a large chunk of a huge sparse matrix

c# - 为什么 .NET 在物理量 >95% 时不将未使用的内存释放回操作系统?

c - 在 C 中同时使用管道标准输入和键盘

c - 如何检查 UTF-8 字符串是否以 'a' 开头

json - $id token 是 JSON 标准吗?

javascript - AngularJS - 尝试信任需要字符串 : Context: html 的内容中的非字符串值

c - 当子进程执行 execvp 时,waitpid 未收到退出状态

c - GLUT 和绘图命令不绘图

JavaScript 数组 : Change elements from string to object