The code below triggers an assertion associated with memory corruption when
compiled with MSVC 9.0 and run. I am using the current version of Xerces
(3.0.1). The documentation at
http://xerces.apache.org/xerces-c/apiDocs-3/classBase64.html#b0de37a376ae7355c973250a66b3a77asays
that I should use XMLString::release to free the memory, however that
is not possible without worrying casts, and in any case the documentation
has been amended to say that delete should be used instead
https://issues.apache.org/jira/browse/XERCESC-1847?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel.
What am I doing wrong?

BTW, anyone facing the same problem can just use a trivial custom memory
manager as a workaround, assuming it is a xerces bug and there is no better
solution.

Many thanks for your help.

#include <stdexcept>
#include <cstring>
#include <xercesc/util/Base64.hpp>
#include <iostream>

int main ()
{
                    const char * data = "hello";
                    XMLSize_t n = 0;
                    XMLByte * b64(
                                  xercesc::Base64::encode(
reinterpret_cast<const XMLByte*>(data),
                                  (unsigned int)(std::strlen (data)), &n) );
                    if (!b64)
                    {
                        throw(std::runtime_error("Unable to base64 encode
data"));
                    }

                    std::cout << "encode(\"" << data << "\") = " << b64 <<
std::endl;
                    delete b64;  // memory corrupted here
                    return 0;
}

Reply via email to