DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9561>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9561

XMLRefVectorOf holding arrays: new[] vs. plain delete

           Summary: XMLRefVectorOf holding arrays: new[] vs. plain delete
           Product: Xerces-C++
           Version: 1.7.0
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Utilities
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


In several places in the Xerces-C++ code, an XMLRefVectorOf is used to hold 
elements which are arrays of XMLCh's (strings). These arrays are created 
with "new []". But when ~XMLRefVectorOf is invoked, it attempts to delete 
these elements with plain "delete", not "delete []". This is generally a C++ 
no-no.

One example is in XMLString:tokenizeString(). There are other places. There 
may be arrays of other things besides XMLCh's also; I haven't checked the 
code base carefully.

The problem is that the data structure is not really a vector of Ref's; it's 
a vector of arrays.

I can think of a couple of ways to fix this (but this is just a user 
talking):

1. Create a template class XMLVectorOfArraysOf<> which is almost the same 
sam XMLRefVectorOf<>, except that the destructor uses "delete []" on the 
elements. (Pick a better name if you like.)

2. More hackish: pass a flag in the constructor or as a template arg 
(maybe?) that indicates that the elements are really arrays.


I would like to thank mpatrol for catching this. We were looking for storage 
leaks in some code that uses Xerces-C++, and mpatrol complained about the 
mismatched new[]/delete.

Regards,
Dan Halbert

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to