Alberto Massari wrote:
pundog wrote:
Hi, i've noticed the leak when running the following code:

while(true)
{
XMLTranscoder* utf8Transcoder;
XMLTransService::Codes failReason;
utf8Transcoder =
XMLPlatformUtils::fgTranscService->makeNewTranscoderFor("UTF-8", failReason,
16*1024);

size_t len = XMLString::stringLen(value);
XMLByte* utf8 = new XMLByte[(len*4)+1];
unsigned int eaten;
unsigned int utf8Len = utf8Transcoder->transcodeTo(my_hebrew_string, len,
utf8, len*4, eaten, XMLTranscoder::UnRep_Throw);

utf8[utf8Len] = '\0';
string str = (char*)utf8;

delete[] utf8;
You also need to release the transcoder

   utf8Transcoder->release();

BTW, I would create it just once outside the 'while' loop.

As for the std::string -> XMLCh* conversion, just use the transcodeFrom method exposed by the same transcoder.
Note that this works only with the proper transcoder for the encoding of the bytes. Obviously, if you transcoded from UTF-16 to UTF-8 to create the std::string instance, you're OK. But if you got the std::string from somewhere else, you'll need to know the encoding for the bytes and create the appropriate transcoder to convert them to UTF-16.

Dave

Reply via email to