List Info

Thread: Help: memory leak ??




Help: memory leak ??
user name
2006-08-22 08:07:27
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&gt;
#include <libxml/tree.h>
#include <string.h>


char *testxml = "<GETINFO><NODENAME name=\&quot;main.diylinux.org\&quot; command=\&quot;GETINFO\" /> \
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   <cpu load=\&quot;3010.714\" /> \
 &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  <UPTIME>53768.39 52310.89&lt;/UPTIME&gt;</GETINFO>&quot;;

static void
print_element_names(xmlNode * a_node)
{
  ;  xmlNode *cur_node = NULL;
&nbsp; &nbsp; xmlChar *key;
&nbsp; &nbsp; xmlChar *category;
 &nbsp;  xmlChar&nbsp; *keys;
&nbsp; &nbsp; xmlChar *value;

&nbsp;   for (cur_node = a_node; cur_node; cur_node = cur_node-&gt;next) {

 &nbsp;   ; &nbsp; if (cur_node->type == XML_ELEMENT_NODE) {

 &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   category = (xmlChar*)cur_node-&gt;name;
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  while( cur_node-&gt;properties ) {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  key = (xmlChar*) cur_node-&gt;properties->name;
 &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;  value = xmlGetProp( cur_node, key);
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; //printf(&quot;%s/%s = %s\n", category, key, value);

  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   cur_node-&gt;properties = cur_node-&gt;properties->next;
 &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; }
 &nbsp; &nbsp;   ; }

 &nbsp;   ; &nbsp; print_element_names(cur_node->;children);
 &nbsp;  }

}


int
test()
{
  ;  xmlDoc *doc = NULL;
&nbsp; &nbsp; xmlNode *root_element = NULL;

&nbsp; &nbsp; //if (argc != 2)
 &nbsp;   // &nbsp; return(1);

 &nbsp;  LIBXML_TEST_VERSION

  ;  /*parse the file and get the DOM */
 &nbsp;  //doc = xmlReadFile(argv[1], NULL, 0);
 ; &nbsp; doc = xmlParseMemory( testxml, strlen( testxml ) );

   ; if (doc == NULL) {
 &nbsp; &nbsp;   ; return 1;
 &nbsp;  }

 &nbsp;  /*Get the root element node */
 &nbsp;  root_element = xmlDocGetRootElement(doc);
 ; &nbsp; print_element_names(root_element);

   ; xmlFreeDoc(doc);

&nbsp; &nbsp;  xmlCleanupParser();

  ;  return 0;
}


int main(void)
{
 &nbsp; &nbsp;   ; int i;
 &nbsp;   ; &nbsp; for( i =0; i<100; i++) {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; test();
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  sleep(1);
 &nbsp; &nbsp; &nbsp;  }
 &nbsp; &nbsp;   ; 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.

Help: memory leak ??
user name
2006-08-22 09:57:54
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);

  h
ttp://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/v
irtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillardredhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ |
Rpmfind RPM search engine  http://rpmfind.net/
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )