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 hichem <hi...@yahoo.ca> on 2007/03/15 23:39:56 UTC

memroy leak

I am having a memory leak with the following code. I am using xerce 2.7.
I am getting a memory leak proportionate to the size of document been
serialized.

Please let me know if I am dong something wrong.

RWCString XMLHelper::serializeDocument(DOMDocument *doc)
{
	DOMWriter*	writer = 0;
	XMLCh* result = 0;
	XMLPlatformUtils::Initialize();

	if (!doc)
		return RWCString();

	writer = ((DOMImplementationLS*)m_impl)->createDOMWriter();
	result = writer->writeToString(*(DOMNode*)doc->getDocumentElement());
	RWCString tempStr = XMLString::transcode(result);	
               XMLString::release(&result); 
	writer->release();
	
                XMLPlatformUtils::Terminate();
	return result;
	}
    

}
-- 
View this message in context: http://www.nabble.com/memroy-leak-tf3411440.html#a9505113
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.

Re: memroy leak

Posted by hichem <hi...@yahoo.ca>.
Thank you Dave for your help. The problem is fixed now.
RWCString is the RogueWave String class. 
http://www.roguewave.com/support/docs/sourcepro/edition8/html/toolsref/rwcstring.html
--
Hichem

David Bertoni wrote:
> 
> hichem wrote:
>> I am having a memory leak with the following code. I am using xerce 2.7. 
>> I am getting a memory leak proportionate to the size of document been 
>> serialized. Please let me know if I am dong something wrong. RWCString 
>> XMLHelper::serializeDocument(DOMDocument *doc) { DOMWriter* writer = 0; 
>> XMLCh* result = 0; XMLPlatformUtils::Initialize(); if (!doc) return 
>> RWCString(); *writer = 
>> ((DOMImplementationLS*)m_impl)->createDOMWriter(); result = 
>> writer->writeToString(*(DOMNode*)doc->getDocumentElement()); RWCString 
>> tempStr = XMLString::transcode(result);* XMLString::release(&result); 
>> writer->release(); XMLPlatformUtils::Terminate(); return result; } }
> 
> It's probably the result of the call to XMLString::transcode(result), 
> although it's hard to say, since I don't know what "RWCString" is.
> 
> try:
>      char* buf = XMLString::transcode(result);
>      RWCString tempStr(buf);
>      XMLString::release(&buf);
> 
> Also, it seems very broken that you free "result" then return that. 
> Perhaps you mean "return tempStr;" instead?
> 
> Dave
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/memroy-leak-tf3411440.html#a9553944
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.


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


Re: memroy leak

Posted by David Bertoni <db...@apache.org>.
hichem wrote:
> I am having a memory leak with the following code. I am using xerce 2.7. 
> I am getting a memory leak proportionate to the size of document been 
> serialized. Please let me know if I am dong something wrong. RWCString 
> XMLHelper::serializeDocument(DOMDocument *doc) { DOMWriter* writer = 0; 
> XMLCh* result = 0; XMLPlatformUtils::Initialize(); if (!doc) return 
> RWCString(); *writer = 
> ((DOMImplementationLS*)m_impl)->createDOMWriter(); result = 
> writer->writeToString(*(DOMNode*)doc->getDocumentElement()); RWCString 
> tempStr = XMLString::transcode(result);* XMLString::release(&result); 
> writer->release(); XMLPlatformUtils::Terminate(); return result; } }

It's probably the result of the call to XMLString::transcode(result), 
although it's hard to say, since I don't know what "RWCString" is.

try:
     char* buf = XMLString::transcode(result);
     RWCString tempStr(buf);
     XMLString::release(&buf);

Also, it seems very broken that you free "result" then return that. 
Perhaps you mean "return tempStr;" instead?

Dave

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