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

memory leak with XInclude

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.1.4
    • 3.2.0
    • XInclude
    • Linux Ubuntu 10.10 i386

    Description

      When xerces-c++ is parsing files with XInclude, it leaks memory. You can check the memory leak by running "valgrind".

      This behavior can be reproduced both with the "XInclude" binary and with custom code.

      All you need to do is:

      • create a parser
      • set validation scheme to Val_Auto
      • setDoNamespaces(true)
      • setDoXInclude(true)
      • parser.parse("example.xml");

      I have tracked the bug. The "actual" leak is inside XIncludeUtils::reportError. It uses XMLPlatformUtils::loadMsgSet, which calls loadAMsgSet, which allocates memory and returns to its callee (see XMLPlatformUtils::loadAMsgSet inside utils/PlatformUtils.cpp). The memory allocated by loadAMsgSet is never freed.

      The solution:
      In file xinclude/XIncludeUtils.cpp, function XIncludeUtils::reportError, the pointer allocated by XMLPlatformUtils::loadMsgSet should be freed. For my testings, I just added a "delete erMsgLoader" at the end of the scope, but I am not sure this is enough (since I'm not sure if any of the functions between loadMsgSet and the end of the scope can throw exceptions). It is up to you, developers, find a proper solution =D

      I'll attach examples.

      I locally tested my patch (I rebuild the Ubuntu package) and it seems to have worked, but I didn't test much. I am not familiar with xerces-c code so I'm not sure if it can break anything.

      Thanks,
      Paulo

      Attachments

        1. xinclude-leak.patch
          0.5 kB
          Paulo Zanoni
        2. xinclude-example.xml
          0.4 kB
          Paulo Zanoni
        3. xinclude_leak.cpp
          1 kB
          Paulo Zanoni

        Activity

          People

            amassari Alberto Massari
            pzanoni Paulo Zanoni
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: