[xsd-users] Bug in ACE CDR deserialization
James Frullo
jamesfrullo at gmail.com
Tue Jul 24 17:16:44 EDT 2007
I just downloaded the latest stable release of xsd (2.3.1), and I tried
compiling and running the "binary" sample under the examples/cxx/tree/binary
directory. I built ACE by linking to the Multi-threaded Debug DLL version
of the CRT, but I built the sample using the plain Multi-threaded Debug
version. This brought out a non-obvious bug in the implementation of the
following function:
inline istream<ACE_InputCDR>& operator>> (istream<ACE_InputCDR>& s,
std::basic_string<char>& x)
This function has the following implementation:
ACE_CDR::Char* r;
if (!s.impl ().read_string (r))
throw ace_cdr_stream_extraction ();
auto_array<ACE_CDR::Char> ar (r);
x = r;
return s;
The problem with this is that calling read_string() gives you memory
allocated by ACE. But auto_array is going to deallocate that memory by
calling delete[]. Since ACE is compiled and linked separately, it is
incorrect to assume that this will work. In fact, it does not work. It
crashes because using the build configurations I mentioned above. The
correct code would be something like:
ACE_CDR::Char* r;
if (!s.impl ().read_string (r))
throw ace_cdr_stream_extraction ();
try {x = r} catch(...){ACE::strdelete(r);throw;}
ACE::strdelete(r);
return s;
Of course, this is ugly. A nicer way would be to have an ace_auto_str()
class (or whatever).
~James
More information about the xsd-users
mailing list