Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-275

Memory leak parsing XML file

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Resolution: Incomplete
    • 1.5
    • None
    • None
    • Operating System: Other
      Platform: PC
    • 5311

    Description

      I got severe memory leaks when i parse XML Files with DOMParser class and using
      DTD validation.

      Here the simple main() routine of the test application:

      void main()
      {
      try

      { // Initialize DCM Environment (includes XMLPlatformUtils::Initialize()) cout << endl << "Initializing DCM environment..." << endl; DCMEnvironment::InitEnv(); cout << "successful" << endl; }

      catch(MissingEnvVariableException& e)

      { cout << endl << "Failure during initializing DCM environment!" << endl; cout << "Reason: " << e.getDescription() << endl; return; }

      catch(ParserInitializationException& e)

      { cout << endl << "Failure during initializing DCM environment!" << endl; cout << "Reason: " << e.getDescription() << endl; return; }

      catch(ModulesInitializationException& e)

      { cout << endl << "Failure during initializing DCM environment!" << endl; cout << "Reason: " << e.getDescription() << endl; return; }

      catch(...)

      { cout << endl << "Failure during initializing DCM environment!" << endl; cout << "Reason: unknown" << endl; return; }

      // run the test
      testLoad_ImgSequence();

      // Clean up DCM Environment (includes XMLPlatformUtils::Terminate())
      Diamant::DCM_L::DCMEnvironment::ExitEnv();

      int result=0;
      result = _CrtDumpMemoryLeaks();
      }

      Here the parsing method:

      void testLoad_ImgSequence()
      {
      ImageSequence* imgSeq=NULL;

      int count=0;
      while(count<100)
      {
      try

      { imgSeq = new ImageSequence ("d:\\Repository\\Is\\", "flicker.xml"); }

      catch (InvalidParameterException& e)

      { imgSeq=NULL; }
      catch (DatafilebaseNotUniqueException& e)
      { imgSeq=NULL; }

      catch (ParserErrorException& e)

      { imgSeq=NULL; }
      catch (XMLFileIOException& e)
      { imgSeq=NULL; }

      catch (...)

      { imgSeq=NULL; }

      // clean up
      if (imgSeq!=NULL) delete imgSeq;

      cout << "ImageSequence loaded." << endl;

      count++;
      }
      }

      With each creation of a ImageSequence instance the given XML file is parsed and
      some attributes in DOM are read:

      ImageSequence::ImageSequence(...)
      {
      //...
      // now load the image sequence data from xml
      DOM_Element imageSeq = _XmlDocument.getDocumentElement();

      // did we have a image sequence?
      if(imageSeq!=NULL)
      {
      DOM_NamedNodeMap ISAttributes = imageSeq.getAttributes();
      DOM_Node attribute;
      DOMString attrName;
      DOMString attrValue;

      char* attrNameVal;
      char* attrValueVal;

      for(int32_t count=0;count<ISAttributes.getLength();count++)

      { attribute = ISAttributes.item(count); attrName = attribute.getNodeName(); attrValue = attribute.getNodeValue(); attrNameVal = attrName.transcode(); attrValueVal = attrValue.transcode(); // initialize the attributes of the image sequence if (!strcmp(attrNameVal,"FPS")) _Fps = atoi(attrValueVal); //... delete attrNameVal; delete attrValueVal; }

      }

      The instrumentalized the Xerces Debug Lib with the Boundschecker and got a lot
      of memory leaks, e.g.:

      QName::QName(QName* const qname) constructor:
      line: fLocalPart = new XMLCh[fLocalPartBufSz + 1];

      unsigned int ElemStack::addChild(QName* const child, const bool toParent)
      method:
      curRow->fChildren[curRow->fChildCount++] = new QName(child);

      etc.

      I hope you can give some comments immediately.
      Thanks in advance.

      Attachments

        Activity

          People

            Unassigned Unassigned
            alfred.wertner@joanneum.at Alfred Wertner
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: