Hi Vitaly,

Thank you for your assistance. 

For reference, here is the code that works without any memory leak:

        std::string Message::convertToString(void) 
        {       
                DOMImplementation* impl = 
DOMImplementation::getImplementation(); 

                DOMLSSerializer   *theSerializer =
((DOMImplementationLS*)impl)->createLSSerializer(); 

                XMLCh* toTranscode = theSerializer->writeToString(pDoc);
                
                char* xmlChar = XMLString::transcode(toTranscode);
                
                std::string transcodedStr;              
                transcodedStr = string(xmlChar);

                XMLString::release(&xmlChar);
                XMLString::release(&toTranscode);
                theSerializer->release(); 
                return transcodedStr; 
        } 


Vitaly Prapirny wrote:
> 
> brendanr wrote:
>>> On 2/26/2010 12:24 PM, brendanr wrote:
>>>> You are correct that I need to release the XMLCh* that is returned from
>>>> transcode. But this is not the leak.
> 
> You should release the char* that is returned from transcode.
> This is the leak definitely:
> 
>>              transcodedStr = std::string(XMLString::transcode(toTranscode)); 
>> //
>> remove
> 
> Here you should save the pointer returned by transcode and release it
> after the std::string is initialized.
> 
> Good luck!
>       Vitaly
> 
> 

-- 
View this message in context: 
http://old.nabble.com/writeToString-memory-Leak-tp27720774p27743015.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.

Reply via email to