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
);
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:
<note >
<id>1362 653</id>
<password>123456 POMHTUY</password>
</note>
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)
The mxml is v2.10.
What I have tried:
How can i do? Thanks