[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xerces-c-dev
Subject:    [jira] Created: (XERCESC-1486) Memory leak in error cases
From:       "Stephan Irrgang (JIRA)" <xerces-c-dev () xml ! apache ! org>
Date:       2005-08-29 12:37:04
Message-ID: 1616085344.1125319024889.JavaMail.jira () ajax ! apache ! org
[Download RAW message or body]

Memory leak in error cases
--------------------------

         Key: XERCESC-1486
         URL: http://issues.apache.org/jira/browse/XERCESC-1486
     Project: Xerces-C++
        Type: Bug
  Components: SAX/SAX2  
    Versions: 2.6.0    
 Environment: HP-UX B.11.11 U 9000/800
aCC: HP ANSI C++ B3910B A.03.57
 Reporter: Stephan Irrgang


Hi,

I found a memory leak using the SAX Parser  in error cases like file not found or \
unexcepted end of file. I first detected it with Xerces C++ release 2.3, and then \
verified that  it's still in contained in the latest release (2.6). Here's the source \
code I used to test this issue; in this example the XML file to parse is not \
existing.

#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/sax/AttributeList.hpp>
#include <xercesc/parsers/SAXParser.hpp>
#include <iostream.h>

using namespace XERCES_CPP_NAMESPACE;

class myCallbackHandler_c : public HandlerBase
{
public:
  void fatalError (const SAXParseException& exception)
  {
    char chBuffer[256];
    XMLString::transcode(exception.getMessage(), chBuffer, 255); 
    throw chBuffer;
  }
};

int main()
{
  int returnValue = 0;
  XMLPlatformUtils::Initialize();
  SAXParser *saxParserPtr = new SAXParser;
  myCallbackHandler_c *callbackHandlerPtr = new myCallbackHandler_c;
  saxParserPtr->setErrorHandler(callbackHandlerPtr);
  
  try
    {
      saxParserPtr->parse("FileNotFound.xml");
    }
  catch (const char* s)
    {
      cerr << s << endl;
      returnValue = 1;
    }
  catch (...)
    {
      cerr << "Unknown exception!" << endl;
      returnValue = 1;
    }
  
  delete callbackHandlerPtr;
  delete saxParserPtr;
  XMLPlatformUtils::Terminate();
  cout << "Returning: " << returnValue << endl;
  return returnValue;
}


When running it with Rational Purify it shows following memory leaks (BTW, the same \
leaks are shown when using HP WDB's memory check functionality).  MLK: 186 bytes \
leaked at 0x400bbd08  This memory was allocated from:
               malloc         [rtlib.o]
               __nW__fUl      [libCsup.2]
               operator new(unsigned long) [rtlib.o]
               xercesc_2_6::MemoryManagerImpl::allocate(unsigned long) \
                [libxerces-c.sl.26.0]
               xercesc_2_6::XMLException::XMLException(const \
                xercesc_2_6::XMLException &)%2 [libxerces-c.sl.26.0]
               xercesc_2_6::IGXMLScanner::scanReset(const xercesc_2_6::InputSource &) \
                [libxerces-c.sl.26.0]
               xercesc_2_6::IGXMLScanner::scanDocument(const xercesc_2_6::InputSource \
                &) [libxerces-c.sl.26.0]
               xercesc_2_6::XMLScanner::scanDocument(const unsigned short *) \
                [libxerces-c.sl.26.0]
               xercesc_2_6::XMLScanner::scanDocument(const char *) \
                [libxerces-c.sl.26.0]
               xercesc_2_6::SAXParser::parse(const char *) [libxerces-c.sl.26.0]
               main           [xerces_mlk.cc:29]
               _start         [libc.2]
               $START$        [crt0.o]
               $START$        [crt0.o]
         MLK: 18 bytes leaked at 0x400a7b18
         This memory was allocated from:
               malloc         [rtlib.o]
               __nW__fUl      [libCsup.2]
               operator new(unsigned long) [rtlib.o]
               xercesc_2_6::MemoryManagerImpl::allocate(unsigned long) \
                [libxerces-c.sl.26.0]
               static xercesc_2_6::XMLString::replicate(const char \
                *,xercesc_2_6::MemoryManager *) [libxerces-c.sl.26.0]
               xercesc_2_6::XMLException::XMLException(const \
                xercesc_2_6::XMLException &)%2 [libxerces-c.sl.26.0]
               xercesc_2_6::IGXMLScanner::scanReset(const xercesc_2_6::InputSource &) \
                [libxerces-c.sl.26.0]
               xercesc_2_6::IGXMLScanner::scanDocument(const xercesc_2_6::InputSource \
                &) [libxerces-c.sl.26.0]
               xercesc_2_6::XMLScanner::scanDocument(const unsigned short *) \
                [libxerces-c.sl.26.0]
               xercesc_2_6::XMLScanner::scanDocument(const char *) \
                [libxerces-c.sl.26.0]
               xercesc_2_6::SAXParser::parse(const char *) [libxerces-c.sl.26.0]
               main           [xerces_mlk.cc:29]
               _start         [libc.2]
               $START$        [crt0.o]
               $START$        [crt0.o]

To me it seems the XMLException object is not released in case an exception is thrown \
in an error handler's fatalError method.  Any ideas? Thanks in advance!

Regards,
Stephan

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic