[xml] libxml memory problem.....
- From: Matt White <matt white albertsons com>
- To: "'xml gnome org'" <xml gnome org>
- Subject: [xml] libxml memory problem.....
- Date: Mon, 24 Sep 2001 01:18:51 -0600
I've been working on a project using libxml2-2.2.7 (which was current at the
time my project began (I'm running it on two different platforms: Solaris
2.7 x86 and AT&T SVR4 3.02).
I've been using the xmlmemory functions to try and chase down a memory leak
and I've mocked up some code to reproduce what I've been seeing. After
constructing a DOM with a SOAP envelope I added a single node and then copy
the entire contents of the DOM to a buffer using xmlDocDumpMemory, then I
release the DOM with xmlFreeDoc.
The problem here in the example code is that xmlMemUsed still reports 224
bytes of memory allocated after the xmlFreeDoc function was called. I would
have expected the amount used to be 0 after the xmlFreeDoc? If I run this
code in a loop the 224 bytes increment with each iteration through the code.
The culprit seems to xmlDocDumpMemory, but I've also seen similar behavior
out of xmlSetProp, and others.
#include <stdio.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libghttp/ghttp.h>
#include <libghttp/ghttp_constants.h>
#define XML_SOAP_ENVELOPE_URL "http://schemas.xmlsoap.org/soap/envelope/"
#define XML_SOAP_ENCODING_URL "http://schemas.xmlsoap.org/soap/encoding/"
#define DEBUG_MEMORY
#define MEM_LIST
int main(void)
{
xmlDocPtr doc;
xmlNodePtr tree, subtree;
xmlNsPtr ns;
xmlChar *buf;
int len;
xmlInitMemory();
doc = xmlNewDoc(XML_DEFAULT_VERSION);
printf("xmlMemUsed at start = %d\n", xmlMemUsed());
doc->children = xmlNewDocNode(doc, NULL, "SOAP:Envelope", NULL);
ns = xmlNewNs(doc->children, XML_SOAP_ENVELOPE_URL, "SOAP");
xmlNewNsProp(doc->children, ns, "encodingStyle", XML_SOAP_ENCODING_URL);
subtree = xmlNewChild(doc->children, NULL, "SOAP:Body", NULL);
tree = xmlNewChild(subtree, NULL, "foobar", "content");
xmlDocDumpMemory(doc, &buf, &len);
printf("buf[%d]=\n%s\n", len, buf);
free(*buf);
xmlCleanupParser();
xmlFreeDoc(doc);
printf("xmlMemUsed at end = %d : is this amount leaked ?\n",
xmlMemUsed());
xmlMemoryDump();
return(0);
}
# ./xmltest
xmlMemUsed at start = 84
buf[208]=
<?xml version="1.0"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"
SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP:Body>
<foobar/>
</SOAP:Body>
</SOAP:Envelope>
xmlMemUsed at end = 224 bytes : is this amount of memory leaked ?
# cat .memdump
Mon Sep 24 01:09:00 2001
MEMORY ALLOCATED : 224, MAX was 5614
BLOCK NUMBER SIZE TYPE
0 26 224 malloc() in parser.c(939) [<?xml version="1.0"?>]
I sure I must be doing something wrong here I'm just not sure what it is.
Could someone point me in the right direction?
Any help would be greatly appreciated,
-Matt
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]