Details
Description
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 deallocate (void *p)
{ free (p); }};
static TinyMemoryManager *s_tmmgr = NULL;
class XStr
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
XStr(const char* const toTranscode)
~XStr()
{ XMLString::release(&fUnicodeForm); } // -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
const XMLCh* unicodeForm() const
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;
}