[
http://issues.apache.org/jira/browse/XALANC-589?page=comments#action_12360475 ]
Ying-Yi Huang commented on XALANC-589:
--------------------------------------
The following test program runs both the good requests and bad requests. The
memory usage is static while the good requests are processed but it grows
substantially when the bad reqests causing exceptions. "USING_XERCES_V1_DEP"
is compiling option to switch between XALAN1.3/XERCES1.6 and XALAN1.8/XERCES2.6.
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <stdio.h>
// Base header file. Must be first.
#if defined (USING_XERCES_V1_DEP)
#include <Include/PlatformDefinitions.hpp>
#include <cassert>
#include <util/PlatformUtils.hpp>
#include <util/XMLException.hpp>
#include <framework/MemBufInputSource.hpp>
#include <framework/LocalFileInputSource.hpp>
#include <XalanDOM/XalanDocument.hpp>
#include <XPath/XObject.hpp>
#include <XPath/XPathEvaluator.hpp>
#include <XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
#include <XalanSourceTree/XalanSourceTreeInit.hpp>
#include <XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
#include <XPath/XPathEnvSupportDefault.hpp>
#include <XPath/ElementPrefixResolverProxy.hpp>
#else
#include <xalanc/Include/PlatformDefinitions.hpp>
#include <cassert>
#if defined(XALAN_CLASSIC_IOSTREAMS)
#include <iostream.h>
#else
#include <iostream>
#endif
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/framework/LocalFileInputSource.hpp>
#include <xercesc/framework/MemBufInputSource.hpp>
#include <xalanc/PlatformSupport/XSLException.hpp>
#include <xalanc/XalanDOM/XalanDocument.hpp>
#include <xalanc/XPath/XObject.hpp>
#include <xalanc/XPath/XPathEvaluator.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeInit.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
#include <xalanc/XPath/XObject.hpp>
#include <xalanc/XPath/XPathEvaluator.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeInit.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
#include <xalanc/XPath/XPathEnvSupportDefault.hpp>
#include <xalanc/XPath/ElementPrefixResolverProxy.hpp>
using namespace xercesc;
using namespace xalanc;
#endif
static const char* MemBufId = "xml_message";
XalanSourceTreeDOMSupport * theDOMSupportPtr = NULL;
XalanSourceTreeParserLiaison * theLiaisonPtr = NULL;
int parseXMLMessage(const char*);
int XPathConfig_Create()
{
int result = 0;
try
{
XMLPlatformUtils::Initialize();
XPathEvaluator::initialize();
theDOMSupportPtr = new XalanSourceTreeDOMSupport();
theLiaisonPtr = new XalanSourceTreeParserLiaison(*theDOMSupportPtr);
// Initialize the XalanSourceTree subsystem...
XalanSourceTreeInit theSourceTreeInit;
// Hook the two together...
theDOMSupportPtr->setParserLiaison(theLiaisonPtr);
return result;
}
catch(...)
{
cerr << "Exception caught in parsing the config file" << endl;
return -1;
}
}
void XPathConfig_CleanUp()
{
try
{
delete theDOMSupportPtr;
delete theLiaisonPtr;
XPathEvaluator::terminate();
XMLPlatformUtils::Terminate();
}
catch (...)
{
cerr << "Exception caught on cleanup " << endl;
}
}
int main(int argc, char *argv[])
{
const char* bad_req = "<ETBpsaMessage> \
<BpsaMessage>\
<TradeBkkpg>\
<account/> \
<security_adp_nbr>\
</security_adp_nbr>\
<currency_cd>000</currency_cd>\
<HIST>\
<HIR>\
<desc_history_txt1>000000052410300 ]]LOCAL.DAT </desc_history_txt1>\
<desc_history_txt2>NOT LOADED] ]]LOCATION]]>, DE
</desc_history_txt2><desc_history_txt3>REFID
:534116005955;\
</desc_history_txt3>\
<desc_history_txt4/>\
<desc_history_txt5/>\
<desc_history_txt6/>\
</HIR>\
</HIST>\
<BAL>\
<BAA/>\
<BAB/>\
</BAL>\
</TradeBkkpg>\
</BpsaMessage>\
</ETBpsaMessage>";
const char* good_req="<ETBpsaMessage>\
<BpsaMessage>\
<TradeBkkpg>\
<account/>\
<security_adp_nbr>\
</security_adp_nbr>\
<currency_cd>000</currency_cd>\
<HIST>\
<HIR>\
<desc_history_txt1>000000052410300LOCAL.DAT </desc_history_txt1>\
<desc_history_txt2>NOT LOADEDLOCATION, DE
</desc_history_txt2><desc_history_txt3>REFID:534116
005955;\
</desc_history_txt3>\
<desc_history_txt4/>\
<desc_history_txt5/>\
<desc_history_txt6/>\
</HIR>\
</HIST>\
<BAL>\
<BAA/>\
<BAB/>\
</BAL>\
</TradeBkkpg>\
</BpsaMessage>\
</ETBpsaMessage>";
if (0 != XPathConfig_Create())
return -1;
struct timeval sleep_time;
memset(&sleep_time, 0, sizeof(sleep_time));
sleep_time.tv_sec=10;
int i;
for (i=0; i< 100000; i++)
{
cerr << "good req " << i << endl;
if (0 != parseXMLMessage(good_req))
return -1;
select( 0, NULL, NULL, NULL, &sleep_time );
}
for (i=0; i< 100000; i++)
{
cerr << "bad req " << i << endl;
parseXMLMessage(bad_req);
select( 0, NULL, NULL, NULL, &sleep_time );
}
XPathConfig_CleanUp();
}
int parseXMLMessage(const char* request)
{
int retcode=0;
try
{
const MemBufInputSource memBuf((const XMLByte*)request,
strlen(request),
MemBufId,
false);
// Parse the document...
XalanDocument* const inputDoc =
theLiaisonPtr->parseXMLStream(memBuf);
theLiaisonPtr->destroyDocument(inputDoc);
return retcode;
}
catch(XalanDOMException e)
{
cerr << "XalanDOMException caught in parsing the XML msg:" <<
e.getExceptionCode() << endl;
return -1;
}
catch (const XSLException & e)
{
XalanDOMString msg(e.getMessage());
char message[256];
for (int i = 0; i < msg.length() && msg.length() < 256; i++)
message[i] = msg[i];
message[i] = '\0';
cerr << "XSLException caught in parsing the XML message: " << message <<
endl;
return -1;
}
catch (...)
{
cerr << "Other exception caught in parsing the XML message" << endl;
return -1;
}
}
> Memory leaks when exception occurs during parsing XML doc
> ---------------------------------------------------------
>
> Key: XALANC-589
> URL: http://issues.apache.org/jira/browse/XALANC-589
> Project: XalanC
> Type: Bug
> Components: XalanC
> Versions: 1.3.x
> Reporter: Ying-Yi Huang
>
> When an illegal XML document in a memory buffer is passed to
> XalanSourceTreeParserLiaison.parseXMLStream(MemBufInputSource), it causes
> exception. But the default exception doesn't free some allocated memory.
> This happens to Xalan 1.3 on RH7.2 and 1.8 on AS3.4. This is a segment of my
> code:
> try {
> const MemBufInputSource memBuf((const XMLByte*)request,
> strlen(request),
> MemBufId,
> false);
> // Parse the document...
> XalanDocument* const inputDoc =
> theLiaisonPtr->parseXMLStream(memBuf);
> }
> catch (...)
> {
> return -1;
> }
--
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]