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 "Alberto Massari (JIRA)" <xe...@xml.apache.org> on 2004/12/06 11:53:23 UTC

[jira] Updated: (XERCESC-1301) XMLString::release uses 'delete' even when MemoryManager is specified in XMLString::transcode().

     [ http://nagoya.apache.org/jira/browse/XERCESC-1301?page=history ]

Alberto Massari updated XERCESC-1301:
-------------------------------------

    Assign To: Alberto Massari
         type: Improvement  (was: Bug)
     Priority: Minor  (was: Major)

The problem lies in the code you have written: once you use the version of XMLString::transcode that accepts a MemoryManager, you should directly invoke MemoryManager::deallocate to release the string buffer. I am turning this bug into a PCR, so that there will be a version of XMLString::release that accepts a MemoryManager too, and does the right thing.

Alberto

> XMLString::release uses 'delete' even when MemoryManager is specified in XMLString::transcode().
> ------------------------------------------------------------------------------------------------
>
>          Key: XERCESC-1301
>          URL: http://nagoya.apache.org/jira/browse/XERCESC-1301
>      Project: Xerces-C++
>         Type: Improvement
>   Components: Utilities
>     Versions: 2.4.0
>  Environment: Windows XP, MS Visual C++ 7.0.
>     Reporter: Kode Charlie
>     Assignee: Alberto Massari
>     Priority: Minor

>
> The problem is this:
> 0. Specify a MemoryManager to XMLString::transcode().
> 1. Call XMLString::release() on the XMLCh* you obtained in step (0).
> 2. Observe that an exception occurs.
> BoundsChecker shows that XMLString::release() is still calling
> 'delete' on the XMLCh**, even though we have specified our own
> (de)allocation with the MemoryManager.
> The code below captures the problem:
> class TinyMemoryManager : public MemoryManager {
>   void *allocate (size_t size)
>   {
>     void *retval = malloc (size);
>     return retval;
>   }
>   void deallocate (void *p)
>   {
>     free (p);
>   }
> };
> static TinyMemoryManager *s_tmmgr = NULL;
> class XStr
> {
> public :
>     // -----------------------------------------------------------------------
>     //  Constructors and Destructor
>     // -----------------------------------------------------------------------
>     XStr(const char* const toTranscode)
>     {
>       // Call the private transcoding method
>       fUnicodeForm = XMLString::transcode (toTranscode, s_tmmgr);
>     }
>     ~XStr()
>     {
>       XMLString::release(&fUnicodeForm);
>     }
>     // -----------------------------------------------------------------------
>     //  Getter methods
>     // -----------------------------------------------------------------------
>     const XMLCh* unicodeForm() const
>     {
>       return fUnicodeForm;
>     }
> private :
>     // -----------------------------------------------------------------------
>     //  Private data members
>     //
>     //  fUnicodeForm
>     //      This is the Unicode XMLCh format of the string.
>     // -----------------------------------------------------------------------
>     XMLCh* fUnicodeForm;
> };
> int main (int argc, char *argv[])
> {
>   s_tmmgr = new TinyMemoryManager();
>   XMLCh *ch = somethingGoesHereThatReturnsAnXMLCh();
>   if (XMLString::compareString (ch, X ("root")))      // Fatal exception here.
>     printf ("matched root\n");
>   return 1;
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://nagoya.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


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