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 Robert Buck <rb...@mathworks.com> on 2003/10/28 20:40:29 UTC

Purify Error showing up in Xerces-C XMLString and/or XMLRefVectorOf

Running Purify on Xerces-C reveals some things that concern us. "Freeing mismatched memory" errors.

In a nutshell: You should use delete[], otherwise the destructor associated with the memory cannot be run. In this particular case it is of little consequence, since there are no destructors associated to a vector of raw Unicode chars. But stylistically, it's not too kosher.

Is there anything you can do to resolve this problem in future releases?

Does anyone run Purify on Xerces-C before a new version of the product is released, in order to prevent these sorts of issues from being introduced to other products?

Bob

##########################################################################

FMM: Freeing mismatched memory (26 times)                               
      This is occurring while in:                                         
            void operator delete(void*) [rtlib.o]                         
            RefVectorOf<unsigned short>::~RefVectorOf()                   
[libxerces-c.so.21]                                                        
            void XMLScanner::parseSchemaLocation(const unsigned            
short*const) [libxerces-c.so.21]                                           
            void XMLScanner::scanRawAttrListforNameSpaces(const            
RefVectorOf<KVStringPair>*,int) [libxerces-c.so.21]                        
            bool XMLScanner::scanStartTagNS(bool&) [libxerces-c.so.21]    
            bool XMLScanner::scanContent(const bool) [libxerces-c.so.21]  
      Attempting to free block at 0x7598b0 in the heap.                   
      Address 0x7598b0 is at the beginning of a malloc'd block of 68      
bytes.                                                                     
      This block was allocated from:                                      
            malloc         [rtlib.o]                                      
            c2n6Fi_Pv___1  [libCrun.so.1]                                 
            void*operator new(unsigned) [rtlib.o]                         
            void*operator new[](unsigned) [rtlib.o]                       
            RefVectorOf<unsigned short>*XMLString::tokenizeString(const    
unsigned short*const) [libxerces-c.so.21]                                  
            void XMLScanner::parseSchemaLocation(const unsigned            
short*const) [libxerces-c.so.21]                                           
      This block of memory was obtained using an allocation routine which  
is                                                                         
      not compatible with the routine by which it is being freed.       

#############################################################################

RefVectorOf<XMLCh>* XMLString::tokenizeString(const XMLCh* const tokenizeSrc)
{
//...
    RefVectorOf<XMLCh>* tokenStack = new RefVectorOf<XMLCh>(16, true);
//...
        XMLCh* token = new XMLCh[skip+1-index];  // <<< array new-expression
//...
        tokenStack->addElement(token);
//...
}

template <class TElem> RefVectorOf<TElem>::~RefVectorOf()
{
    if (this->fAdoptedElems)
    {
       for (unsigned int index = 0; index < this->fCurCount; index++)
        delete this->fElemList[index];  // <<< mismatched operator delete !!!
    }
    fMemoryManager->deallocate(this->fElemList);//delete [] this->fElemList;
}