[ 
http://issues.apache.org/jira/browse/XERCESC-1433?page=comments#action_12312869 
] 

Jesse Pelton commented on XERCESC-1433:
---------------------------------------

DOMWriter::writeToString() allocates the string that it returns to the caller. 
If there's a bug here, it's in the documentation, which does not mention that 
it's the caller's responsibility to release the string, or how to do so, unlike 
the documentation for (e.g.) some versions of XMLString::replicate(). (There's 
some variation in the documentation for the different versions of this method, 
which should perhaps be another bug.)

As for the problem at hand, calling XMLString::release(&xXml) should do the 
trick. Is that what "did not work out?" If so, what happened?

Please continue this discussion on the mailing list, which is the appropriate 
place for it. It's not clear yet that there's a bug in the library.

> Memory leak with WriteToString
> ------------------------------
>
>          Key: XERCESC-1433
>          URL: http://issues.apache.org/jira/browse/XERCESC-1433
>      Project: Xerces-C++
>         Type: Bug
>   Components: DOM
>     Versions: 2.6.0
>  Environment: HP-UX 11i and compiler HP ANSI C++ B3910B A.03.52
>     Reporter: Biju George

>
> Using a simple serializeDOM function and in long run shows memory leak
> XERCES_CPP_NAMESPACE_USE
>     int serializeDOM(DOMImplementation *impl, DOMNode* node, char * strError, 
> char * outString) {
>         DOMWriter* theSerializer = 
> ((DOMImplementationLS*)impl)->createDOMWriter();
>     try 
>     {
>               XMLCh *xXml = theSerializer->writeToString(*node); 
>               char *pChar = XMLString::transcode(xXml); 
>               strcpy(outString,pChar);
>         }
>         catch (const XMLException& toCatch) {
>             char* message = XMLString::transcode(toCatch.getMessage());
>             strError = message;
>             XMLString::release(&message);
>             return FAILURE;
>         }
>         catch (const DOMException& toCatch) {
>             char* message = XMLString::transcode(toCatch.msg);
>             strError = message;
>             XMLString::release(&message);
>             return FAILURE;
>         }
>         catch (...) {
>         strcpy(strError, "Unexpected Exception\n");
>             return FAILURE;
>         }
>         theSerializer->release();
>         return 0;
>     }
> Commenting out the line               XMLCh *xXml = 
> theSerializer->writeToString(*node);  will show that there is no memory leak. 
> So I think the writeString method has the leak. Let me know whether I am 
> doing something wrong or a fix for the same is available. I am using 
> XERCESC++ version 2.6.0. Deleting xXml also did not work out for me. 

-- 
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]

Reply via email to