[xml] memory leak?



I was able to build libxml2-2.6.22 on AIX 4.3.3.

I wrote a server program that calls a function that uses xml2's XPath 
functions to get a value for some tag.

I monitor the program size with ps -el and see that program size is 
increasing.  When I don't call my function in the server, the program size is 
constant.

Before I exit the function I call the three cleanup functions a part of xml2. 
i.e. /* Cleanup */
     xmlXPathFreeObject( xpathObj );
     xmlXPathFreeContext( xpathCtx );
     xmlFreeDoc( doc );

I followed http://www.xmlsoft.org/examples/xpath1.c as an example.

Can someone suggest something?

long int
getLogXmlStartTime( const char *xmlbuf )
{
     int                size;
     long int           startTime = -1;
     xmlNodePtr         cur;
     xmlDocPtr          doc;
     xmlXPathContextPtr xpathCtx;
     xmlXPathObjectPtr  xpathObj;
     xmlNodeSetPtr      nodes;

     BUGIN1( getLogXmlStartTime, %x, xmlbuf )

     /* Load XML document */
     doc = xmlParseMemory( xmlbuf, strlen(xmlbuf) );
     if ( doc == NULL ){
          fprintf( stderr, "Error: unable to parse xml \"%s\"\n", xmlbuf );
          BUGRET1( getLogXmlStartTime - unable to parse xml document, %x, -1 )
     }

     /* Create xpath evaluation context */
     xpathCtx = xmlXPathNewContext( doc );
     if ( xpathCtx == NULL ){
          fprintf( stderr, "Error: unable to create new XPath context\n" );
          xmlFreeDoc( doc );
          BUGRET1( getLogXmlStartTime - unable to create new XPath context, 
%x, -1 )
     }

     /* Evaluate xpath expression */
     xpathObj = xmlXPathEvalExpression( LOG_START_TIME_XPATH_EXPR, xpathCtx );
     if ( xpathObj == NULL ){
          fprintf( stderr, "Error: unable to evaluate xpath expression 
\"%s\"\n", LOG_START_TIME_XPATH_EXPR );
          xmlXPathFreeContext( xpathCtx );
          xmlFreeDoc( doc );
          BUGRET1( getLogXmlStartTime - unable to evaluate xpath expression, 
%x, -1 )
     }

     nodes = xpathObj->nodesetval;
     size = (nodes) ? nodes->nodeNr : 0;
     if ( size > 0 ){
          cur = nodes->nodeTab[ 0 ];
          if ( cur != NULL )
               startTime = atoi( cur->content );
     }

     /* Cleanup */
     xmlXPathFreeObject( xpathObj );
     xmlXPathFreeContext( xpathCtx );
     xmlFreeDoc( doc );

     BUGRET1( getLogXmlStartTime, %x, startTime )
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]