[xml] memory leakages when parsing
- From: "Volker Roth" <pulken gmx net>
- To: <xml gnome org>
- Subject: [xml] memory leakages when parsing
- Date: Mon, 25 Oct 2004 15:32:27 +0200
Hello,
we find memory leakages in the following situation:
An xml-File references an Entity defined in the DTD
The File is parsed by
xmlReadFile(pFilename, NULL,
XML_PARSE_DTDVALID |
XML_PARSE_NOENT |
XML_PARSE_DTDLOAD |
XML_PARSE_DTDATTR);
After freeing the xmlDocPtr and clearing the xmlParser,
=====================================================================
=================< the report from MSVCPP(W2K) is:
=========================
=====================================================================
Detected memory leaks!
Dumping objects ->
{226} normal block at 0x0031E448, 8 bytes long.
Data: <nbktext > 6E 62 6B 74 65 78 74 00
{225} normal block at 0x0031A030, 8 bytes long.
Data: <nbktext > 6E 62 6B 74 65 78 74 00
Object dump complete.
=====================================================================
=========< Output from Valgrind on Libxmlversion 2.6.14:
=========================
=====================================================================
==22765== 144 bytes in 18 blocks are definitely lost in loss record 3 of 4
==22765== at 0x1B902E20: malloc (in
/usr/lib/valgrind/vgpreload_memcheck.so)
==22765== by 0x1B9A7F31: xmlStrndup (xmlstring.c:45)
==22765== by 0x1B9A7FC1: xmlStrdup (xmlstring.c:71)
==22765== by 0x1B94C160: xmlParseReference (parser.c:5596)
=====================================================================
====================< Comment >======================================
=====================================================================
The leakage is confirmed by valgrind on linux too,
libxml-Versions are 2.6.7 and 2.6.14.
Moreover, it does not vanish, when we work explicitely with a parsercontext.
How can the leakage be avoided?
=====================================================================
====================< DTD >==========================================
=====================================================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!ELEMENT rnode (f)>
<!ELEMENT f (#PCDATA)>
<!ATTLIST f
att1 CDATA #FIXED 'J'>
<!ENTITY f
"
<f>
hello world
</f>
"
=====================================================================
====================< XML >==========================================
=====================================================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE rnode SYSTEM "hallowelt.dtd">
<rnode>
&f;
</rnode>
=====================================================================
====================< Source >=======================================
=====================================================================
#include <CRTDBG.H>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
void DebInit(void)
{
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
tmpFlag |= _CRTDBG_ALLOC_MEM_DF; /* Turn on debug allocation */
tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF; /* Check heap every alloc/dealloc */
tmpFlag |= _CRTDBG_LEAK_CHECK_DF; /* Leak check at program exit */
_CrtSetDbgFlag( tmpFlag );
}
xmlDocPtr schablone_GetSchabloneFilename(const char* pFilename);
xmlDocPtr schablone_GetSchabloneFilename(const char* pFilename)
{
xmlDocPtr pSchablone = NULL;
pSchablone = xmlReadFile(pFilename, NULL, XML_PARSE_DTDVALID |
XML_PARSE_NOENT |
XML_PARSE_DTDLOAD |
XML_PARSE_DTDATTR);
if (pSchablone == NULL)
{
return NULL;
}
return pSchablone;
}
int main(int argc, char *argv[])
{
xmlDocPtr pDomOut = NULL;
DebInit();
pDomOut = schablone_GetSchabloneFilename("C:\\hallowelt.xml");
xmlFreeDoc(pDomOut),
xmlCleanupParser();
printf("main ende\n");
return 0;
}
thanks in advance
Volker Roth
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]