用户mxml和用户valgrind有内存泄漏 [英] User mxml and user valgrind have memory leak
本文介绍了用户mxml和用户valgrind有内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是代码:
main:
This is code:
main:
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include"mxml.h"
int main(int argc,char **arv)
{
FILE *fp;
mxml_node_t *tree,*node;
fp = fopen("test.xml", "r");
if(fp == NULL)
{
return 1;
}
tree = mxmlLoadFile(NULL, fp,MXML_OPAQUE_CALLBACK);
fclose(fp);
mxml_node_t *id,*password;
node = mxmlFindElement(tree, tree, "note",
NULL, NULL,MXML_DESCEND
/*MXML_DESCEND*/);
id = mxmlFindElement(node, tree, "id",
NULL, NULL,
MXML_DESCEND);
printf("[%s]\n",id->child->value.opaque);
password = mxmlFindElement(node, tree, "password",
NULL, NULL,
MXML_DESCEND);
printf("[%s]\n",password->child->value.opaque);
mxmlDelete(tree);
return 0;
}
XML:
XML:
<note >
<id>1362 653</id>
<password>123456 POMHTUY</password>
</note>
然后用户valgrind结果:
Then user valgrind result:
valgrind --tool=memcheck --leak-check=yes ./main
==27151== Memcheck, a memory error detector
==27151== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==27151== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==27151== Command: ./main
==27151==
==27151==
==27151== HEAP SUMMARY:
==27151== in use at exit: 149 bytes in 6 blocks
==27151== total heap usage: 22 allocs, 16 frees, 933 bytes allocated
==27151==
==27151== 149 (88 direct, 61 indirect) bytes in 2 blocks are definitely lost in loss record 3 of 3
==27151== at 0x4006041: calloc (vg_replace_malloc.c:593)
==27151== by 0x804C875: mxml_new (mxml-node.c:805)
==27151== by 0x804CA1A: mxmlNewElement (mxml-node.c:392)
==27151== by 0x804A0E4: mxml_load_data (mxml-file.c:1955)
==27151== by 0x804A8A8: mxmlLoadFile (mxml-file.c:164)
==27151== by 0x80488FC: main (exeso.c:14)
==27151==
==27151== LEAK SUMMARY:
==27151== definitely lost: 88 bytes in 2 blocks
==27151== indirectly lost: 61 bytes in 4 blocks
==27151== possibly lost: 0 bytes in 0 blocks
==27151== still reachable: 0 bytes in 0 blocks
==27151== suppressed: 0 bytes in 0 blocks
==27151==
==27151== For counts of detected and suppressed errors, rerun with: -v
==27151== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 8)
mxml是v2.10。
我尝试过:
The mxml is v2.10.
What I have tried:
How can i do? Thanks
推荐答案
参见主人的mxml / CHANGES.md·michaelrsweet / mxml·GitHub [ ^ ]:
See mxml/CHANGES.md at master · michaelrsweet/mxml · GitHub[^]:
引用:
Mini的变化-XML 2.11
...
修复了mxmlDelete中的内存泄漏问题(问题#183)
Changes in Mini-XML 2.11
...
Fixed a memory leak in mxmlDelete (Issue #183)
所以你应该升级到版本2.11。
So you should upgrade to version 2.11.
这篇关于用户mxml和用户valgrind有内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文