[xsd-users] Core dump on xercesc_3_2::RefVectorOf<char16_t>::~RefVectorOf()

Javier Gutierrez javier.gutierrez at web.de
Mon Nov 8 02:31:14 EST 2021


Hello Boris,



I am trying to implement the embedded sample into my project.

I have put the creation and loading of the grammar pool into the constructor
of a class.

Then the parsing of the XML into a member function.

For that I have the grammar pool (xercesc::XMLGrammarPool) and the parser
(xercesc::DOMLSParser) as private members

If I don't have a destructor defined, everything runs fine.

Once I define the destructor I get a core dump.



Any idea how to overcome the problem?



Environment:

*	Ubuntu 18.04
*	xsd-4.0.0-x86_64-linux-gnu
*	Gcc 10.3.0
*	Xercesc 3.2



Here the back-trace:



Program received signal SIGSEGV, Segmentation fault.

0x0000000000000000 in ?? ()

(gdb) where

#0  0x0000000000000000 in ?? ()

#1  0x00007ffff79d33a9 in xercesc_3_2::RefVectorOf<char16_t>::~RefVectorOf()
() from /usr/lib/x86_64-linux-gnu/libxerces-c-3.2.so

#2  0x00007ffff79d30a9 in
xercesc_3_2::DOMStringListImpl::~DOMStringListImpl() () from
/usr/lib/x86_64-linux-gnu/libxerces-c-3.2.so

#3  0x00007ffff7a52c20 in xercesc_3_2::DOMLSParserImpl::~DOMLSParserImpl()
() from /usr/lib/x86_64-linux-gnu/libxerces-c-3.2.so

#4  0x00007ffff7a52d09 in xercesc_3_2::DOMLSParserImpl::~DOMLSParserImpl()
() from /usr/lib/x86_64-linux-gnu/libxerces-c-3.2.so

#5  0x000055555555c5d7 in
xsd::cxx::xml::dom::auto_ptr<xercesc_3_2::DOMLSParser>::reset (x=0x0,
this=0x7fffffffdae8)

    at ../../../../libxsd/xsd/cxx/xml/dom/auto-ptr.hxx:216

#6  xsd::cxx::xml::dom::auto_ptr<xercesc_3_2::DOMLSParser>::~auto_ptr
(this=0x7fffffffdae8, __in_chrg=<optimized out>)

    at ../../../../libxsd/xsd/cxx/xml/dom/auto-ptr.hxx:120

#7  XsdWrapper::~XsdWrapper (this=0x7fffffffdae0, __in_chrg=<optimized out>)
at driver.cxx:191

#8  0x000055555555be27 in main (argc=<optimized out>, argv=0x7fffffffdb30)
at driver.cxx:210



Here the driver.cxx adapted to recreate the problem:



// file      : examples/cxx/tree/embedded/driver.cxx

// copyright : not copyrighted - public domain



#include <memory>   // std::auto_ptr

#include <fstream>

#include <iostream>



#include <xercesc/dom/DOM.hpp>

#include <xercesc/util/XMLUniDefs.hpp> // chLatin_*

#include <xercesc/util/PlatformUtils.hpp>

#include <xercesc/validators/common/Grammar.hpp> // xercesc::Grammar

#include <xercesc/framework/Wrapper4InputSource.hpp>



#include <xercesc/framework/XMLGrammarPoolImpl.hpp>



#include <xsd/cxx/xml/string.hxx>

#include <xsd/cxx/xml/dom/auto-ptr.hxx>

#include <xsd/cxx/xml/dom/bits/error-handler-proxy.hxx>

#include <xsd/cxx/xml/sax/std-input-source.hxx>



#include <xsd/cxx/tree/error-handler.hxx>



#include "library.hxx"

#include "library-schema.hxx"

#include "grammar-input-stream.hxx"



using namespace std;



class XsdWrapper

{

private:

    std::unique_ptr<xercesc::XMLGrammarPool> gp;

    xsd::cxx::xml::dom::auto_ptr<xercesc::DOMLSParser> parser;

    xsd::cxx::tree::error_handler<char> eh;



public:

    XsdWrapper()

    {

        // We need to initialize the Xerces-C++ runtime because we

        // are doing the XML-to-DOM parsing ourselves.

        //

        xercesc::XMLPlatformUtils::Initialize ();



        try

        {

            namespace xml = xsd::cxx::xml;



            // Create and load the grammar pool.

            //

            xercesc::MemoryManager* mm
(xercesc::XMLPlatformUtils::fgMemoryManager);



            gp = std::make_unique<xercesc::XMLGrammarPoolImpl> (mm);



            try

            {

                grammar_input_stream is (library_schema, sizeof
(library_schema));

                gp->deserializeGrammars(&is);

            }

            catch(const xercesc::XSerializationException& e)

            {

                cerr << "unable to load schema: " <<

                    xml::transcode<char> (e.getMessage ()) << endl;

                // return 1;

            }



            // Lock the grammar pool. This is necessary if we plan to use
the

            // same grammar pool in multiple threads (this way we can reuse
the

            // same grammar in multiple parsers). Locking the pool disallows
any

            // modifications to the pool, such as an attempt by one of the
threads

            // to cache additional schemas.

            //

            gp->lockPool ();



            // Get an implementation of the Load-Store (LS) interface.

            //

            const XMLCh ls_id [] = {xercesc::chLatin_L, xercesc::chLatin_S,
xercesc::chNull};



            xercesc::DOMImplementation* impl (

                    xercesc::DOMImplementationRegistry::getDOMImplementation
(ls_id));



            parser.reset (

                    impl->createLSParser (

                        xercesc::DOMImplementationLS::MODE_SYNCHRONOUS, 0,
mm, gp.get ()));



            xercesc::DOMConfiguration* conf (parser->getDomConfig ());



            // Discard comment nodes in the document.

            //

            conf->setParameter (xercesc::XMLUni::fgDOMComments, false);



            // Enable datatype normalization.

            //

            conf->setParameter (xercesc::XMLUni::fgDOMDatatypeNormalization,
true);



            // Do not create EntityReference nodes in the DOM tree. No

            // EntityReference nodes will be created, only the nodes

            // corresponding to their fully expanded substitution text

            // will be created.

            //

            conf->setParameter (xercesc::XMLUni::fgDOMEntities, false);



            // Perform namespace processing.

            //

            conf->setParameter (xercesc::XMLUni::fgDOMNamespaces, true);



            // Do not include ignorable whitespace in the DOM tree.

            //

            conf->setParameter
(xercesc::XMLUni::fgDOMElementContentWhitespace, false);



            // Enable validation.

            //

            conf->setParameter (xercesc::XMLUni::fgDOMValidate, true);

            conf->setParameter (xercesc::XMLUni::fgXercesSchema, true);

            conf->setParameter (xercesc::XMLUni::fgXercesSchemaFullChecking,
false);



            // Xerces-C++ 3.1.0 is the first version with working multi
import

            // support.

            //

#if _XERCES_VERSION >= 30100

            conf->setParameter
(xercesc::XMLUni::fgXercesHandleMultipleImports, true);

#endif



            // Use the loaded grammar during parsing.

            //

            conf->setParameter
(xercesc::XMLUni::fgXercesUseCachedGrammarInParse, true);



            // Disable loading schemas via other means (e.g.,
schemaLocation).

            //

            conf->setParameter (xercesc::XMLUni::fgXercesLoadSchema, false);



            // We will release the DOM document ourselves.

            //

            conf->setParameter
(xercesc::XMLUni::fgXercesUserAdoptsDOMDocument, true);



            // Set error handler.

            //

            xml::dom::bits::error_handler_proxy<char> ehp (eh);

            conf->setParameter (xercesc::XMLUni::fgDOMErrorHandler, &ehp);



        }

        catch (const xml_schema::exception& e)

        {

            cerr << e << endl;

            // r = 1;

        }

    }



    void parse(const std::string &inputFileName)

    {

        try

        {

            // Parse XML documents.

            //

            for (unsigned long i (0); i < 10; ++i)

            {

                ifstream ifs;

                ifs.exceptions (ifstream::badbit | ifstream::failbit);

                ifs.open (inputFileName);



                // Wrap the standard input stream.

                //

                xsd::cxx::xml::sax::std_input_source isrc (ifs,
inputFileName);

                xercesc::Wrapper4InputSource wrap (&isrc, false);



                // Parse XML to DOM.

                //

                xml_schema::dom::auto_ptr<xercesc::DOMDocument> doc
(parser->parse (&wrap));



               eh.throw_if_failed<xml_schema::parsing> ();



                // Parse DOM to the object model.

                //

                auto_ptr<library::catalog> c (library::catalog_ (*doc));



                cerr << "catalog with " << c->book ().size () << " books" <<
endl;

            }

        }

        catch (const xml_schema::exception& e)

        {

            cerr << e << endl;

            // r = 1;

        }

        catch (const std::ios_base::failure&)

        {

            cerr << inputFileName << ": unable to open or read failure" <<
endl;

            // r = 1;

        }

    }



    ~XsdWrapper()

    {

        xercesc::XMLPlatformUtils::Terminate ();

    }

};



int

main (int argc, char* argv[])

{

  if (argc != 2)

  {

    cerr << "usage: " << argv[0] << " library.xml" << endl;

    return 1;

  }



  int r (0);



  XsdWrapper xsdWrapper;

  xsdWrapper.parse(argv[1]);



  return r;

}



Thanks and best regards,

Javier Gutierrez

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6009 bytes
Desc: not available
Url : https://codesynthesis.com/pipermail/xsd-users/attachments/20211108/f5082871/smime.bin


More information about the xsd-users mailing list