You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by y_...@tsmc.com on 2008/12/09 01:42:35 UTC

MemBufInputSource Core Dump

Dear Sir :
                  I use xerces for parsing XML String , I found some
question in my test

                 platform : IBM AIX 5.2
                 complier : IBM VA C++
                 xerces version : 2-8-0

                Q1. xerces can support multi-thread ?  ( I found answer in
xerces faq from http://xerces.apache.org/xerces-c/faq-parse-3.html#faq-6 )
                      need you double confirm

                Q2. In my function , always core dump in ( new
MemBufInputSource )
                      I use C++ while function for test xerces have memory
leak

                Q3. If I use C++ delete function delete xerces object ,
                       why xerces still have memory leak  ?

                Q4. MemBufInputSource have limit  usage ?


                attach file is my function


Source Code
=========================================================================================
try
{
    XMLPlatformUtils::Initialize();

    PPT_METHODTRACE_V1( "" , "================== Now Starting Parse XML
==================" ) ;
    string XMLString = (const char * )xmlContextInfoSeq[i].xmlContext ;
    string parseString = "";
    PPT_METHODTRACE_V2( "" , " XMLString :" , XMLString.c_str() );

    string bufferId = "prodInfo" ;
    MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager;
    MemoryManager* const manager2 = XMLPlatformUtils::fgMemoryManager;

    MemBufInputSource* memBufIS = new MemBufInputSource ((const
XMLByte*)XMLString.c_str(),

strlen(XMLString.c_str()),
                                                         bufferId.c_str(),
                                                         false,
                                                         manager2
                                                         );

    DOMInputSource * inSource = new Wrapper4InputSource(memBufIS,true,
manager);
    DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(X(""));

    DOMBuilder* parser = ((DOMImplementationLS*)impl)->
createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);

    DOMDocument* xmlDoc;
    xmlDoc =  parser->parse(*inSource);
    DOMElement * root = xmlDoc->getDocumentElement();
    DOMNodeList * list = xmlDoc->getElementsByTagName(X("ObjInfo"));

    //=============================//
    //  XMLSize_t Use Size_t       //
    //  default start from value 0 //
    //=============================//
    for ( XMLSize_t index_Attr = 0 ; index_Attr < list->getLength() ;
index_Attr++ )
    {
        DOMElement * elem =
static_cast<DOMElement*>(list->item(index_Attr)) ;
        string lot_id = "" ;
        string eqp_id = "" ;
        string value = "" ;

        objectIdentifier mem_control ;
        const XMLCh * tmpxmlch = elem->getAttribute(X("ObjType"));
        mem_control.identifier = XMLString::transcode(tmpxmlch);
        value = (const char *)mem_control.identifier ;

        PPT_METHODTRACE_V2( "" , " Objtype value :" , value.c_str() );

        if ( value == "Equipment" )
        {
            objectIdentifier mem_control2 ;
            const XMLCh * tmpxmlch2 = elem->getAttribute(X("Value"));
            mem_control2.identifier = XMLString::transcode(tmpxmlch2);
            eqp_id = (const char *)mem_control2.identifier;
            PPT_METHODTRACE_V2( "" , " eqp_id :" , eqp_id.c_str() );
            setIDLstring(strObjXMLparse_out.strXMLvalueSeq[i].eqpID ,
eqp_id ) ;
            PPT_METHODTRACE_V2( "" , "
strObjXMLparse_out.strXMLvalueSeq[i].eqpID " ,
strObjXMLparse_out.strXMLvalueSeq[i].eqpID );
        }
        else if ( value == "Lot" )
        {
            objectIdentifier mem_control3 ;
            const XMLCh * tmpxmlch3 = elem->getAttribute(X("Value")) ;
            mem_control3.identifier = XMLString::transcode(tmpxmlch3);
            lot_id = (const char *)mem_control3.identifier ;
            PPT_METHODTRACE_V2( "" , " lot_id :" , lot_id.c_str() );
            setIDLstring(strObjXMLparse_out.strXMLvalueSeq[i].lotID,lot_id)
;
            PPT_METHODTRACE_V2( "" , "
strObjXMLparse_out.strXMLvalueSeq[i].lotID " ,
strObjXMLparse_out.strXMLvalueSeq[i].lotID );
        }

    }
    delete inSource ;
    delete parser ;

}
catch (const XMLException& toCatch)
{
    char* message = XMLString::transcode(toCatch.getMessage());
    PPT_METHODTRACE_V2( "" , "Error during initialization :" , message );
    XMLString::release(&message);
    return 1;
}

XMLPlatformUtils::Terminate();

PPT_METHODTRACE_V1( "" , "================== Now Ending Parse XML
==================" ) ;


Best Regards, Sincerely
 --------------------------------------------------------------------------- 
                                                         TSMC PROPERTY       
 This email communication (and any attachments) is proprietary information   
 for the sole use of its                                                     
 intended recipient. Any unauthorized review, use or distribution by anyone  
 other than the intended                                                     
 recipient is strictly prohibited.  If you are not the intended recipient,   
 please notify the sender by                                                 
 replying to this email, and then delete this email and any copies of it     
 immediately. Thank you.                                                     
 --------------------------------------------------------------------------- 




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


Re: MemBufInputSource Core Dump

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi Nicholas,

Thayer_Nicholas@emc.com <Th...@emc.com> writes:

> So initializing and terminating the xerces-c library could result in 
> a failure?

If you do it from multiple threads and don't have proper synchronization.
See this FAQ item for details:

http://xerces.apache.org/xerces-c/faq-parse-3.html#faq-4

> Also, does each module need to call initialize/terminate on the 
> xerces-c library?  We dynamically load DLLs that use Xerces 
> internally, so any guidance would be helpful.

If your executable is Xerces-aware then the easiest approach 
would be to call Initialize/Terminate from main() and let the
DLLs assume it is initialized.

If this is not the case (e.g., the executable may not know anything
about Xerces-C++), then you will need to call Initialize/Terminate
from each DLL (the support for multiple calls to these functions was
added for this scenario). If DLLs are loaded from the same thread then
you don't need to do anything special. If, however, the libraries may
be loaded from multiple threads concurrently, then you will need to
implement your own synchronization (e.g., a mutex) around calls to
Initialize/Terminate.

Boris

-- 
Boris Kolpackov, Code Synthesis Tools   http://codesynthesis.com/~boris/blog
Open source XML data binding for C++:   http://codesynthesis.com/products/xsd
Mobile/embedded validating XML parsing: http://codesynthesis.com/products/xsde

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


Re: MemBufInputSource Core Dump

Posted by Pranav Savkur <pr...@gmail.com>.
Hello Dave,

         Even i'm using a similar piece of code for XML String parsing with
Xerces 2.8 and Visual Studio 2005.

thsi piece of code goes thru fine the first time but the second time onwards
even for a valid XML, the parse() method throws a generic exception.. i.e
catch(...) block despite having XMLException and DOMException catch blocks

Can you point out any mistakes in the code. this was working fine with
Xerces 2.2 and Visual Studio 6.0

XERCES_CPP_NAMESPACE::XercesDOMParser* m_pDOMParser;

m_pDOMParser = new XERCES_CPP_NAMESPACE::XercesDOMParser;

        DOMTreeErrorReporter *errReporter = new DOMTreeErrorReporter();
        errReporter->resetErrors();

        m_pDOMParser->setErrorHandler(errReporter);
m_pDOMParser->resetDocumentPool();

                CString strSchemaFile;
                CString strSchemaFilePath;
                BOOL bFuncRet =
SPVRegAcc::GetXMLFilePath(strSchemaFilePath);
                strSchemaFile = strSchemaFilePath + _T("\\config\\");
                if(FALSE == m_bDBPatching)
                {
                    strSchemaFile += m_XMLSchemaName;
                }
                else
                {
                    //MOD V5.1.62 get the dbpatch schema
                    strSchemaFile += _T("SPV_DBPatch_Schema.xsd");
                    //MOD V5.1.62 changes end
                }
                TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree()
m_pDOMParser found schema");

                //    m_pDOMParser->setErrorHandler(m_pDOMErrorHandler);



m_pDOMParser->setExternalNoNamespaceSchemaLocation(strSchemaFile);

                //Get all errors
                m_pDOMParser->setExitOnFirstFatalError(true);
                //All validation errors are fatal.
                m_pDOMParser->setValidationConstraintFatal(true);
                //Set the validation scheme

m_pDOMParser->setValidationScheme(XERCES_CPP_NAMESPACE::XercesDOMParser::Val_Auto
);
                //Set schema validation
                m_pDOMParser->setValidationSchemaFullChecking(false);
                //Use namespaces and schema
                //m_pDOMParser->setDoNamespaces(true);
                m_pDOMParser->setDoSchema(true);
                //MOD001V5.2:to correct  DF1487 change start
                m_pDOMParser->setIncludeIgnorableWhitespace(false);


            CT2CA pszConvertedAnsiString (m_XMLFileName);
            std::string strStd (pszConvertedAnsiString);

            const char* pStr = strStd.c_str();
            //const TCHAR* pStr = StringToChar(m_XMLFileName);
            TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() converted
StringToChar");

            MemBufInputSource* memBufIS = new MemBufInputSource(
                 (const XMLByte *)pStr
                ,strlen(pStr)
                , bufId
                , false
                );

            //memBufIS->setPublicId(bufId);
            /*const XMLCh *const chEncoding = _T("UTF-8");
            memBufIS->setEncoding(chEncoding);*/
            TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() formed
MemBufInputSourceObject Successfully");

            m_pDOMParser->setDoNamespaces(false);
            TRACE_INFO("Entering CSPVXMLParserWrapper::CreateDOMTree()
SetDoNamespace set to false");

            m_pDOMParser->parse(*memBufIS);
            TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() Done
parsing");

            delete [] pStr;
            TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() Done deleting
pStr");
            pStr = NULL;
            TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() Set pStr to
NULL");

            TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() trying to
delete memBUFIS");
            delete memBufIS;
            TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() deleted
memBUFIS");
            memBufIS = NULL;
            TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTREE() set memBUFIS
to NULL");

in the release we have
         delete m_pDOMParser;
            m_pDOMParser = 0 ;
m_ppDOMDocument->release();

in a critical section

Please let me know

thanks and regards,
Pranav

On Thu, Dec 11, 2008 at 9:57 AM, <Th...@emc.com> wrote:

> Hello,
>
> So initializing and terminating the xerces-c library could result in a
> failure?  I do this in our source as well, and I don't think we've ever had
> a problem, but am concerned about whether this could result in a very
> hard-to-find error in the future.
>
> Also, does each module need to call initialize/terminate on the xerces-c
> library?  We dynamically load DLLs that use Xerces internally, so any
> guidance would be helpful.
>
> Thanks,
> Nicholas
>
> -----Original Message-----
> From: David Bertoni [mailto:dbertoni@apache.org]
> Sent: Wednesday, December 10, 2008 7:42 PM
> To: c-dev@xerces.apache.org
> Subject: Re: MemBufInputSource Core Dump
>
> y_tzeng@tsmc.com wrote:
> > David ,  thank you for your suggestion
> >
> > 1. In now I already fix my parse function
> > 2. I found the Xercesc-C doc ,
> >     XMLPlatformUtils::Initialize() and XMLPlatformUtils::Terminate()
> >    can use it in after function start and before function end
> > 3. In your suggestion , told me 「Please make sure you're not initializing
> > and terminating Xerces-C ineach thread 」
> >   It's mean in multi-thread env only have once Initialize and Terminate
>  ?
> Yes.  You should initialize the library once before you start processing
> and terminate once when you're done.
>
> The initialization code is not thread-safe, and initializing and
> terminating the library multiple times is very inefficient.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>

RE: MemBufInputSource Core Dump

Posted by Th...@emc.com.
Hello,

So initializing and terminating the xerces-c library could result in a failure?  I do this in our source as well, and I don't think we've ever had a problem, but am concerned about whether this could result in a very hard-to-find error in the future.

Also, does each module need to call initialize/terminate on the xerces-c library?  We dynamically load DLLs that use Xerces internally, so any guidance would be helpful.

Thanks,
Nicholas

-----Original Message-----
From: David Bertoni [mailto:dbertoni@apache.org] 
Sent: Wednesday, December 10, 2008 7:42 PM
To: c-dev@xerces.apache.org
Subject: Re: MemBufInputSource Core Dump

y_tzeng@tsmc.com wrote:
> David ,  thank you for your suggestion
> 
> 1. In now I already fix my parse function
> 2. I found the Xercesc-C doc ,
>     XMLPlatformUtils::Initialize() and XMLPlatformUtils::Terminate()
>    can use it in after function start and before function end
> 3. In your suggestion , told me 「Please make sure you're not initializing
> and terminating Xerces-C ineach thread 」
>   It's mean in multi-thread env only have once Initialize and Terminate  ?
Yes.  You should initialize the library once before you start processing
and terminate once when you're done.

The initialization code is not thread-safe, and initializing and
terminating the library multiple times is very inefficient.

Dave

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



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


Re: MemBufInputSource Core Dump

Posted by David Bertoni <db...@apache.org>.
y_tzeng@tsmc.com wrote:
> David ,  thank you for your suggestion
> 
> 1. In now I already fix my parse function
> 2. I found the Xercesc-C doc ,
>     XMLPlatformUtils::Initialize() and XMLPlatformUtils::Terminate()
>    can use it in after function start and before function end
> 3. In your suggestion , told me 「Please make sure you're not initializing
> and terminating Xerces-C ineach thread 」
>   It's mean in multi-thread env only have once Initialize and Terminate  ?
Yes.  You should initialize the library once before you start processing
and terminate once when you're done.

The initialization code is not thread-safe, and initializing and
terminating the library multiple times is very inefficient.

Dave

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


Re: MemBufInputSource Core Dump

Posted by y_...@tsmc.com.
David ,  thank you for your suggestion

1. In now I already fix my parse function
2. I found the Xercesc-C doc ,
    XMLPlatformUtils::Initialize() and XMLPlatformUtils::Terminate()
   can use it in after function start and before function end
3. In your suggestion , told me 「Please make sure you're not initializing
and terminating Xerces-C ineach thread 」
  It's mean in multi-thread env only have once Initialize and Terminate  ?


Best Regards, Sincerely
 --------------------------------------------------------------------------- 
                                                         TSMC PROPERTY       
 This email communication (and any attachments) is proprietary information   
 for the sole use of its                                                     
 intended recipient. Any unauthorized review, use or distribution by anyone  
 other than the intended                                                     
 recipient is strictly prohibited.  If you are not the intended recipient,   
 please notify the sender by                                                 
 replying to this email, and then delete this email and any copies of it     
 immediately. Thank you.                                                     
 --------------------------------------------------------------------------- 




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


Re: MemBufInputSource Core Dump

Posted by David Bertoni <db...@apache.org>.
y_tzeng@tsmc.com wrote:
> David  thank you for response my question ,
> 
> 1. this is core dump stack trace
> 
>   -- Last Stack Trace
> ---------------------------------------------------------------
> .() at 0x0
This means the program is trying to execute code at address 0, so there
is likely a null pointer to an object.

> XMLString.transcode__Q2_11xercesc_2_89XMLStringFCPCcCPQ2_11xercesc_2_813MemoryManager()
>  at 0x10108810
> InputSource.__ct__Q2_11xercesc_2_811InputSourceFCPCcCPQ2_11xercesc_2_813MemoryManager()
>  at 0x101afc98
> MemBufInputSource.__ct__Q2_11xercesc_2_817MemBufInputSourceFCPCUcCUiCPCcCbCPQ2_11xercesc_2_813MemoryManager()
>  at 0x102fccfc
> bss_ECNS_parseXML.bss_ECNS_parseXML__15BS_PPTManager_iFR25bssObjXMLparse_out_structRC21pptObjCommonIn_structPCcRC28_IDL_SEQUENCE_xmlContextInfoRC22_IDL_SEQUENCE_pptUData(0x3319b4d8,
>  0x33776108, 0x3378e0f8, 0x34922988, 0x337a8100, 0x337a8110) at 0x1009af10
Please make sure you're not initializing and terminating Xerces-C in
each thread.  That is explicitly not thread-safe.  It may be that the
MemoryManager instance is null, or the transcoding system is not
initialized.

> 
> 2. I use while loop for parse xml string , and combine xmlstring
> 
> 3. In my parse XML function I already defind  inline function X for release
> XMLString::transcode
>     class XStr
> {
> public :
>     XStr(const char* const toTranscode)
>     {
>         fUnicodeForm = XMLString::transcode(toTranscode);
>     }
>     ~XStr()
>     {
>         XMLString::release(&fUnicodeForm);
>     }
>     const XMLCh* unicodeForm() const
>     {
>         return fUnicodeForm;
>     }
> private :
>     XMLCh*   fUnicodeForm;
> };
> 
> #define X(str) XStr(str).unicodeForm()
Using this macro is very inefficient.  There are previous message
threads on the  user list that discuss creating compile-time UTF-16
string constants.  Also, please make sure you read the threads regarding
XMLString::transcode() and issues with the local code page.

> 
> 4. mem_controlx is smart point object
>    for control memory from XMLString::transcode( XML CH * ) return
Then why not have an accessor function that returns const char*, rather
than relying on brute-force C-style casting?

Dave

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


Re: MemBufInputSource Core Dump

Posted by y_...@tsmc.com.
David  thank you for response my question ,

1. this is core dump stack trace

  -- Last Stack Trace
---------------------------------------------------------------
.() at 0x0
XMLString.transcode__Q2_11xercesc_2_89XMLStringFCPCcCPQ2_11xercesc_2_813MemoryManager()
 at 0x10108810
InputSource.__ct__Q2_11xercesc_2_811InputSourceFCPCcCPQ2_11xercesc_2_813MemoryManager()
 at 0x101afc98
MemBufInputSource.__ct__Q2_11xercesc_2_817MemBufInputSourceFCPCUcCUiCPCcCbCPQ2_11xercesc_2_813MemoryManager()
 at 0x102fccfc
bss_ECNS_parseXML.bss_ECNS_parseXML__15BS_PPTManager_iFR25bssObjXMLparse_out_structRC21pptObjCommonIn_structPCcRC28_IDL_SEQUENCE_xmlContextInfoRC22_IDL_SEQUENCE_pptUData(0x3319b4d8,
 0x33776108, 0x3378e0f8, 0x34922988, 0x337a8100, 0x337a8110) at 0x1009af10

2. I use while loop for parse xml string , and combine xmlstring

3. In my parse XML function I already defind  inline function X for release
XMLString::transcode
    class XStr
{
public :
    XStr(const char* const toTranscode)
    {
        fUnicodeForm = XMLString::transcode(toTranscode);
    }
    ~XStr()
    {
        XMLString::release(&fUnicodeForm);
    }
    const XMLCh* unicodeForm() const
    {
        return fUnicodeForm;
    }
private :
    XMLCh*   fUnicodeForm;
};

#define X(str) XStr(str).unicodeForm()

4. mem_controlx is smart point object
   for control memory from XMLString::transcode( XML CH * ) return



Best Regards, Sincerely



|--------------------------------->
|            David Bertoni        |
|            <db...@apache.org>|
|                                 |
|                                 |
|            2008/12/09 上午 09:51|
|                                 |
|                                 |
|              Please respond to  |
|            c-dev@xerces.apache.o|
|                     rg          |
|                                 |
|--------------------------------->
  >----------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                      |
  |                                                                                                                      |
  |                                                                                                                    To|
  |        c-dev@xerces.apache.org                                                                                       |
  |                                                                                                                    cc|
  |                                                                                                                      |
  |                                                                                                               Subject|
  |        Re: MemBufInputSource Core Dump                                                                               |
  |                                                                                                                      |
  |                                                                                                                      |
  |                                                                                                                      |
  |                                                                                                                      |
  |                                                                                                                      |
  >----------------------------------------------------------------------------------------------------------------------|




y_tzeng@tsmc.com wrote:
> Dear Sir :
>                   I use xerces for parsing XML String , I found some
> question in my test
>
>                  platform : IBM AIX 5.2
>                  complier : IBM VA C++
>                  xerces version : 2-8-0
>
>                 Q1. xerces can support multi-thread ?  ( I found answer
in
> xerces faq from http://xerces.apache.org/xerces-c/faq-parse-3.html#faq-6
)
>                       need you double confirm
Why do you need confirmation?  If you follow the instructions in the
FAQ, you should not have any problems with using Xerces-C in a
multi-threaded application.

>
>                 Q2. In my function , always core dump in ( new
> MemBufInputSource )
OK, please show us the stack trace for the dump.

>                       I use C++ while function for test xerces have
memory
> leak
I'm afraid I don't understand what you're saying.

>
>                 Q3. If I use C++ delete function delete xerces object ,
>                        why xerces still have memory leak  ?
Perhaps the leak is in your code and not in Xerces-C?

>
>                 Q4. MemBufInputSource have limit  usage ?
I'm not sure what you mean by "limit usage."  As long as you use the
class correctly, it should work as designed.

>
>
>                 attach file is my function
>
>
> Source Code
>
=========================================================================================

> try
> {
>     XMLPlatformUtils::Initialize();
>
>     PPT_METHODTRACE_V1( "" , "================== Now Starting Parse XML
> ==================" ) ;
>     string XMLString = (const char * )xmlContextInfoSeq[i].xmlContext ;
I'm not sure why this cast is necessary.  What is the type of
xmlContextInfoSeq[i]xmlContext?

>     string parseString = "";
>     PPT_METHODTRACE_V2( "" , " XMLString :" , XMLString.c_str() );
>
>     string bufferId = "prodInfo" ;
>     MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager;
>     MemoryManager* const manager2 = XMLPlatformUtils::fgMemoryManager;
>
>     MemBufInputSource* memBufIS = new MemBufInputSource ((const
> XMLByte*)XMLString.c_str(),
>
> strlen(XMLString.c_str()),
Why not use XMLString.length() here?

>
bufferId.c_str(),
>                                                          false,
>                                                          manager2
>                                                          );
>
>     DOMInputSource * inSource = new Wrapper4InputSource(memBufIS,true,
> manager);
You have indicated to Wrapper4InputSource that it owns the object
pointed to by "memBufIS," so it will delete the instance in its destructor.

>     DOMImplementation *impl =
> DOMImplementationRegistry::getDOMImplementation(X(""));
>
>     DOMBuilder* parser = ((DOMImplementationLS*)impl)->
> createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
>
>     DOMDocument* xmlDoc;
>     xmlDoc =  parser->parse(*inSource);
>     DOMElement * root = xmlDoc->getDocumentElement();
>     DOMNodeList * list = xmlDoc->getElementsByTagName(X("ObjInfo"));
>
>     //=============================//
>     //  XMLSize_t Use Size_t       //
>     //  default start from value 0 //
>     //=============================//
>     for ( XMLSize_t index_Attr = 0 ; index_Attr < list->getLength() ;
> index_Attr++ )
>     {
>         DOMElement * elem =
> static_cast<DOMElement*>(list->item(index_Attr)) ;
>         string lot_id = "" ;
>         string eqp_id = "" ;
>         string value = "" ;
>
>         objectIdentifier mem_control ;
>         const XMLCh * tmpxmlch = elem->getAttribute(X("ObjType"));
>         mem_control.identifier = XMLString::transcode(tmpxmlch);
You need to call XMLString::release() on the pointer returned by
XMLString::transcode().  I don't know what the type of
mem_control.identifier is, but this could be a leak.

>         value = (const char *)mem_control.identifier ;
Why do you need this cast?

>
>         PPT_METHODTRACE_V2( "" , " Objtype value :" , value.c_str() );
>
>         if ( value == "Equipment" )
>         {
>             objectIdentifier mem_control2 ;
>             const XMLCh * tmpxmlch2 = elem->getAttribute(X("Value"));
>             mem_control2.identifier = XMLString::transcode(tmpxmlch2);
Again, this may be a leak.

>             eqp_id = (const char *)mem_control2.identifier;
Again, why do you need this cast?

>             PPT_METHODTRACE_V2( "" , " eqp_id :" , eqp_id.c_str() );
>             setIDLstring(strObjXMLparse_out.strXMLvalueSeq[i].eqpID ,
> eqp_id ) ;
>             PPT_METHODTRACE_V2( "" , "
> strObjXMLparse_out.strXMLvalueSeq[i].eqpID " ,
> strObjXMLparse_out.strXMLvalueSeq[i].eqpID );
>         }
>         else if ( value == "Lot" )
>         {
>             objectIdentifier mem_control3 ;
>             const XMLCh * tmpxmlch3 = elem->getAttribute(X("Value")) ;
>             mem_control3.identifier = XMLString::transcode(tmpxmlch3);
Perhaps another leak.

>             lot_id = (const char *)mem_control3.identifier ;
Another strange cast.

>             PPT_METHODTRACE_V2( "" , " lot_id :" , lot_id.c_str() );
>
setIDLstring(strObjXMLparse_out.strXMLvalueSeq[i].lotID,lot_id)
> ;
>             PPT_METHODTRACE_V2( "" , "
> strObjXMLparse_out.strXMLvalueSeq[i].lotID " ,
> strObjXMLparse_out.strXMLvalueSeq[i].lotID );
>         }
>
>     }
>     delete inSource ;
>     delete parser ;
>
> }
> catch (const XMLException& toCatch)
> {
>     char* message = XMLString::transcode(toCatch.getMessage());
>     PPT_METHODTRACE_V2( "" , "Error during initialization :" , message );
>     XMLString::release(&message);
>     return 1;
If you return from this path, you will leave the library initialized.
Since you have no other catch handlers, this could be an exception
that's not from the XMLPlatformUtils::Initialize() call.

> }
>
> XMLPlatformUtils::Terminate();
>
> PPT_METHODTRACE_V1( "" , "================== Now Ending Parse XML
> ==================" ) ;
>
>
> Best Regards, Sincerely
>
---------------------------------------------------------------------------

>                                                          TSMC PROPERTY

>  This email communication (and any attachments) is proprietary
information
>  for the sole use of its

>  intended recipient. Any unauthorized review, use or distribution by
anyone
>  other than the intended

>  recipient is strictly prohibited.  If you are not the intended
recipient,
>  please notify the sender by

>  replying to this email, and then delete this email and any copies of it

>  immediately. Thank you.

>
---------------------------------------------------------------------------

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


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



 --------------------------------------------------------------------------- 
                                                         TSMC PROPERTY       
 This email communication (and any attachments) is proprietary information   
 for the sole use of its                                                     
 intended recipient. Any unauthorized review, use or distribution by anyone  
 other than the intended                                                     
 recipient is strictly prohibited.  If you are not the intended recipient,   
 please notify the sender by                                                 
 replying to this email, and then delete this email and any copies of it     
 immediately. Thank you.                                                     
 --------------------------------------------------------------------------- 




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


Re: MemBufInputSource Core Dump

Posted by David Bertoni <db...@apache.org>.
y_tzeng@tsmc.com wrote:
> Dear Sir :
>                   I use xerces for parsing XML String , I found some
> question in my test
> 
>                  platform : IBM AIX 5.2
>                  complier : IBM VA C++
>                  xerces version : 2-8-0
> 
>                 Q1. xerces can support multi-thread ?  ( I found answer in
> xerces faq from http://xerces.apache.org/xerces-c/faq-parse-3.html#faq-6 )
>                       need you double confirm
Why do you need confirmation?  If you follow the instructions in the 
FAQ, you should not have any problems with using Xerces-C in a 
multi-threaded application.

> 
>                 Q2. In my function , always core dump in ( new
> MemBufInputSource )
OK, please show us the stack trace for the dump.

>                       I use C++ while function for test xerces have memory
> leak
I'm afraid I don't understand what you're saying.

> 
>                 Q3. If I use C++ delete function delete xerces object ,
>                        why xerces still have memory leak  ?
Perhaps the leak is in your code and not in Xerces-C?

> 
>                 Q4. MemBufInputSource have limit  usage ?
I'm not sure what you mean by "limit usage."  As long as you use the 
class correctly, it should work as designed.

> 
> 
>                 attach file is my function
> 
> 
> Source Code
> =========================================================================================
> try
> {
>     XMLPlatformUtils::Initialize();
> 
>     PPT_METHODTRACE_V1( "" , "================== Now Starting Parse XML
> ==================" ) ;
>     string XMLString = (const char * )xmlContextInfoSeq[i].xmlContext ;
I'm not sure why this cast is necessary.  What is the type of 
xmlContextInfoSeq[i]xmlContext?

>     string parseString = "";
>     PPT_METHODTRACE_V2( "" , " XMLString :" , XMLString.c_str() );
> 
>     string bufferId = "prodInfo" ;
>     MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager;
>     MemoryManager* const manager2 = XMLPlatformUtils::fgMemoryManager;
> 
>     MemBufInputSource* memBufIS = new MemBufInputSource ((const
> XMLByte*)XMLString.c_str(),
> 
> strlen(XMLString.c_str()),
Why not use XMLString.length() here?

>                                                          bufferId.c_str(),
>                                                          false,
>                                                          manager2
>                                                          );
> 
>     DOMInputSource * inSource = new Wrapper4InputSource(memBufIS,true,
> manager);
You have indicated to Wrapper4InputSource that it owns the object 
pointed to by "memBufIS," so it will delete the instance in its destructor.

>     DOMImplementation *impl =
> DOMImplementationRegistry::getDOMImplementation(X(""));
> 
>     DOMBuilder* parser = ((DOMImplementationLS*)impl)->
> createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
> 
>     DOMDocument* xmlDoc;
>     xmlDoc =  parser->parse(*inSource);
>     DOMElement * root = xmlDoc->getDocumentElement();
>     DOMNodeList * list = xmlDoc->getElementsByTagName(X("ObjInfo"));
> 
>     //=============================//
>     //  XMLSize_t Use Size_t       //
>     //  default start from value 0 //
>     //=============================//
>     for ( XMLSize_t index_Attr = 0 ; index_Attr < list->getLength() ;
> index_Attr++ )
>     {
>         DOMElement * elem =
> static_cast<DOMElement*>(list->item(index_Attr)) ;
>         string lot_id = "" ;
>         string eqp_id = "" ;
>         string value = "" ;
> 
>         objectIdentifier mem_control ;
>         const XMLCh * tmpxmlch = elem->getAttribute(X("ObjType"));
>         mem_control.identifier = XMLString::transcode(tmpxmlch);
You need to call XMLString::release() on the pointer returned by 
XMLString::transcode().  I don't know what the type of 
mem_control.identifier is, but this could be a leak.

>         value = (const char *)mem_control.identifier ;
Why do you need this cast?

> 
>         PPT_METHODTRACE_V2( "" , " Objtype value :" , value.c_str() );
> 
>         if ( value == "Equipment" )
>         {
>             objectIdentifier mem_control2 ;
>             const XMLCh * tmpxmlch2 = elem->getAttribute(X("Value"));
>             mem_control2.identifier = XMLString::transcode(tmpxmlch2);
Again, this may be a leak.

>             eqp_id = (const char *)mem_control2.identifier;
Again, why do you need this cast?

>             PPT_METHODTRACE_V2( "" , " eqp_id :" , eqp_id.c_str() );
>             setIDLstring(strObjXMLparse_out.strXMLvalueSeq[i].eqpID ,
> eqp_id ) ;
>             PPT_METHODTRACE_V2( "" , "
> strObjXMLparse_out.strXMLvalueSeq[i].eqpID " ,
> strObjXMLparse_out.strXMLvalueSeq[i].eqpID );
>         }
>         else if ( value == "Lot" )
>         {
>             objectIdentifier mem_control3 ;
>             const XMLCh * tmpxmlch3 = elem->getAttribute(X("Value")) ;
>             mem_control3.identifier = XMLString::transcode(tmpxmlch3);
Perhaps another leak.

>             lot_id = (const char *)mem_control3.identifier ;
Another strange cast.

>             PPT_METHODTRACE_V2( "" , " lot_id :" , lot_id.c_str() );
>             setIDLstring(strObjXMLparse_out.strXMLvalueSeq[i].lotID,lot_id)
> ;
>             PPT_METHODTRACE_V2( "" , "
> strObjXMLparse_out.strXMLvalueSeq[i].lotID " ,
> strObjXMLparse_out.strXMLvalueSeq[i].lotID );
>         }
> 
>     }
>     delete inSource ;
>     delete parser ;
> 
> }
> catch (const XMLException& toCatch)
> {
>     char* message = XMLString::transcode(toCatch.getMessage());
>     PPT_METHODTRACE_V2( "" , "Error during initialization :" , message );
>     XMLString::release(&message);
>     return 1;
If you return from this path, you will leave the library initialized. 
Since you have no other catch handlers, this could be an exception 
that's not from the XMLPlatformUtils::Initialize() call.

> }
> 
> XMLPlatformUtils::Terminate();
> 
> PPT_METHODTRACE_V1( "" , "================== Now Ending Parse XML
> ==================" ) ;
> 
> 
> Best Regards, Sincerely
>  --------------------------------------------------------------------------- 
>                                                          TSMC PROPERTY       
>  This email communication (and any attachments) is proprietary information   
>  for the sole use of its                                                     
>  intended recipient. Any unauthorized review, use or distribution by anyone  
>  other than the intended                                                     
>  recipient is strictly prohibited.  If you are not the intended recipient,   
>  please notify the sender by                                                 
>  replying to this email, and then delete this email and any copies of it     
>  immediately. Thank you.                                                     
>  --------------------------------------------------------------------------- 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
> 


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