I'm working in a project and I use the xerces library. When I try to delete a pointer my project crashes.
Here is the source code:
std::ostream& operator<<(std::ostream& target, const DOMString& s)
{
char *p = s.transcode(); // method from xerces
target << p;
delete [] p;
return target;
}
This method works fine in Visual Studio 6 (I'm trying to build in 2010).
From the xerces docs:
NOTE: The returned buffer is dynamically allocated and is the responsibility of the caller to delete it when not longer needed. You can call XMLString::release to release this returned buffer.
It seems that xerces allocates the buffer not with new[]
(perhaps malloc
or some custom allocator). The only way to guarantee that the buffer safely gets deallocated is with: XMLString::release