Re: [xml] Help: memory leak ??
- From: "Taeyoung Hong" <catchrye gmail com>
- To: xml gnome org
- Cc: veillard redhat com
- Subject: Re: [xml] Help: memory leak ??
- Date: Thu, 15 Feb 2007 18:23:44 +0900
I tested the following YuChan's test code by adding "xmlFree(value)"
in while loop like this;
while( cur_node->properties ) {
key = (xmlChar*) cur_node->properties->name;
value = xmlGetProp( cur_node, key);
printf("%s/%s = %s\n", category, key, value);
xmlFree(value);
cur_node->properties = cur_node->properties->next;
}
However, still memory leak occurs.
On one hundred iteration of test() fuction in the code, resident
memory size of the program increased up to 88 KB.
testbed is the linux w/ 2.6.9-5.0.5.ELsmp, x86_64, opteron, CentOS 4.0,
and rpm libxml2-2.6.16-6 was installed
the same test without xmlFree(value) gives the 96 KB memory leaks.
when I tried to test the simplified code like this, which gave us the
same result,
88KB memory leaks,
while( cur_node->properties ) {
cur_node->properties =
cur_node->properties->next;
}
I do not know where this leak comes from.
Plz, let me know that
------------------------------------------------
Re: [xml] Help: memory leak ??
Daniel Veillard
Tue, 22 Aug 2006 02:58:06 -0700
On Tue, Aug 22, 2006 at 05:07:27PM +0900, YuChan Park wrote:
during running the program it comsume 8 or 4 bytes memory whenever call test
function included in blow code.
...
value = xmlGetProp( cur_node, key);
http://xmlsoft.org/html/libxml-tree.html#xmlGetProp
Returns: the attribute value or NULL if not found. It's up to the caller
to free the memory with xmlFree().
no amount of asking will ever replace reading the docs.
Daniel
--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard | virtualization library http://libvirt.org/
[EMAIL PROTECTED] | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
----------------------------------------------------------------------------------------------------------------
[xml] Help: memory leak ??
YuChan Park
Tue, 22 Aug 2006 01:07:39 -0700
Hello.
I wrote some application with libxml2 ( version 2.6.23 ).
but the application comsume the system memory
So for testing i tried to run example program which was written as
like my program.
but the status is same .
during running the program it comsume 8 or 4 bytes memory whenever
call test function included in blow code.
the memory status is observated using top( linux program)
RES included in top is increased continuously during running program..
why does this problem appear??
thanks.
------------------CODE---------------------------------------------
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <string.h>
char *testxml = "<GETINFO><NODENAME name=\"main.diylinux.org\"
command=\"GETINFO\" /> \
<cpu load=\"3010.714\" /> \
<UPTIME>53768.39 52310.89</UPTIME></GETINFO>";
static void
print_element_names(xmlNode * a_node)
{
xmlNode *cur_node = NULL;
xmlChar *key;
xmlChar *category;
xmlChar *keys;
xmlChar *value;
for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
category = (xmlChar*)cur_node->name;
while( cur_node->properties ) {
key = (xmlChar*) cur_node->properties->name;
value = xmlGetProp( cur_node, key);
//printf("%s/%s = %s\n", category, key, value);
cur_node->properties = cur_node->properties->next;
}
}
print_element_names(cur_node->children);
}
}
int
test()
{
xmlDoc *doc = NULL;
xmlNode *root_element = NULL;
//if (argc != 2)
// return(1);
LIBXML_TEST_VERSION
/*parse the file and get the DOM */
//doc = xmlReadFile(argv[1], NULL, 0);
doc = xmlParseMemory( testxml, strlen( testxml ) );
if (doc == NULL) {
return 1;
}
/*Get the root element node */
root_element = xmlDocGetRootElement(doc);
print_element_names(root_element);
xmlFreeDoc(doc);
xmlCleanupParser();
return 0;
}
int main(void)
{
int i;
for( i =0; i<100; i++) {
test();
sleep(1);
}
return 0;
}
-------------------------------------------------END CODE--------------
compile:
gcc -o ttest test.c `libxml2-config --cflags --libs`
./ttest
status: top -p `pidof ttest`
the RES in top increased continuously
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]