[xml] Help: memory leak ??



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]