Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-1301

XMLString::release uses 'delete' even when MemoryManager is specified in XMLString::transcode().

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.0
    • 2.5.0
    • Utilities
    • None
    • Windows XP, MS Visual C++ 7.0.

    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 *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;
      }

      Attachments

        Activity

          People

            amassari Alberto Massari
            kodecharlie Kode Charlie
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: