That's an incredibly unfortunate bit of knowlege... I'm going to have
to fix a lot of programs now. But thanks for the tidbit!
paul.heil@gmail.com wrote:
std::auto_ptr<TCHAR> txt(new TCHAR[len + 1]);
You should not be using auto_ptr to hold an array. What was allocated
with new[] must be deleted with delete[], as in
TCHAR* p = new TCHAR[len + 1];
delete[] p;
Of course auto_ptr doesn't know this and uses regular delete. It works
with VC compiler, but only by accident.
Consider using std::vector instead:
std::vector<TCHAR> vbuf(len + 1);
TCHAR* pbuf = &vbuf.front(); // pointer into vector's internal data
buffer
// vbuf automatically frees the buffer when going out of scope
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925