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 Arun Ramdas <ar...@etrade.com> on 2002/04/03 03:58:42 UTC
Usage of MemBufInputSource
I am creating an inputsource stream from the xml string using,
MemBufInputSource *memBufIS = new MemBufInputSource((const XMLByte *)
request, (sizeof(char) * strlen(request)), gSystemId, false);
then my code piece goes like this,
bool hasErrors = false;
try {
SA_Parser->parse(*memBufIS);
}
catch(const XMLException& e)
{
DOMString dom_str = DOMString(e.getMessage());
char *str_val = dom_str.transcode();
lm_message(LM_VERBOSE,GetProgramName(),SVC_PARSE_ERROR,"SA_ParseXmlMessage",
-1," %d Er
ror during Message Parsing: %s ",
__LINE__ , str_val);
free(str_val);
hasErrors = true;
}
catch(...)
{
hasErrors = true;
}
if(!hasErrors)
{
DOM_Document doc = SA_Parser->getDocument();
ret_doc = doc;
}
else
{
*response = SAFaultError(SVC_PARSE_ERROR, "NONE", FaultActor);
DOM_Document errDoc;
ret_doc = errDoc;
}
Should i need to delete memBufIS , before returning from this function?
Thanks
Arun
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Usage of MemBufInputSource
Posted by Martin Kalen <ma...@todaysystems.com.au>.
Yes, you should delete the object created by operator new by calling
operator delete.
E.g:
delete memBufIS;
memBufIS = 0;
You might also want to revise how you deallocate the memory returned
by DOMString::transcode(), since you are now mixing the C++ operator
new[] and the C-library's free() which can lead to undefined
behaviour.
Rather than:
free(str_val)
do:
delete [] str_val;
str_val = 0;
You can also put the last two lines in the catch (...) block to
prevent memory leaks when catching an exception. (This is the reason
why I always set the pointer to 0, so that any delete calls does not
free free:d memory. Saves you checking for "if (ptr)" for all your
dynamic data.)
HTH,
Martin
----- Original Message -----
From: "Arun Ramdas" <ar...@etrade.com>
To: <xe...@xml.apache.org>
Sent: Wednesday, April 03, 2002 11:58 AM
Subject: Usage of MemBufInputSource
> I am creating an inputsource stream from the xml string using,
>
> MemBufInputSource *memBufIS = new MemBufInputSource((const XMLByte
*)
> request, (sizeof(char) * strlen(request)), gSystemId, false);
>
> then my code piece goes like this,
>
> bool hasErrors = false;
> try {
> SA_Parser->parse(*memBufIS);
> }
> catch(const XMLException& e)
> {
> DOMString dom_str = DOMString(e.getMessage());
> char *str_val = dom_str.transcode();
>
>
lm_message(LM_VERBOSE,GetProgramName(),SVC_PARSE_ERROR,"SA_ParseXmlMes
sage",
> -1," %d Er
> ror during Message Parsing: %s ",
> __LINE__ , str_val);
> free(str_val);
> hasErrors = true;
>
> }
> catch(...)
> {
> hasErrors = true;
> }
> if(!hasErrors)
> {
> DOM_Document doc = SA_Parser->getDocument();
> ret_doc = doc;
> }
> else
> {
> *response = SAFaultError(SVC_PARSE_ERROR, "NONE", FaultActor);
> DOM_Document errDoc;
> ret_doc = errDoc;
> }
>
> Should i need to delete memBufIS , before returning from this
function?
>
> Thanks
> Arun
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org