Release Crash with Ofstream

109 views
Skip to first unread message

fedor.l...@gmail.com

unread,
Feb 3, 2009, 6:34:33 PM2/3/09
to Protocol Buffers
Hi, I'm trying to use protobuf and am experiencing a release mode
static initialization crash. Specifically a crash in
FileOptions::Clear(). Partial stack trace follows the message.

We're using MS Visual C++ 2005 to compile libprotobuf.lib and
libprotoc.lib statically (rev 89, 2.0.4-SNAPSHOT), and link to the CRT
statically. Our project gets compiled (also via MSVC++ 2005) into a
DLL and links to MFC and the CRT statically as well (/MT). We're
experiencing this crash when a process loads our project dll. Now the
peculiar thing is that we've narrowed it down to being able to trigger
the crash with just a single line:

std::ofstream out;

If we define an ofstream object anywhere, even locally in a function,
then the dll fails to load and crashes. This doesn't occur in debug
mode. I've tried disabling most optimizations, and I've found that
that
didn't make a difference. We've also had trouble reproducing this in
example projects which don't seem to be any different from our live
project, except perhaps being simpler. Our project doesn't link to any
other 3rd party libraries except whatever gets pulled in with MFC and
Windows (which hasn't given us any issues similar before).

We did try compiling protobuf and our project to link to the CRT
dynamically
and that seemed to get rid of this issue, but for various reasons
we're
interested in having it work with linking to the CRT statically.

I'm looking for ideas as to what may be causing this. I'm concerned
ofstream
isn't the only thing involved with this and would like to avoid
potential
future issues. Any ideas would be much appreciated.

Fedor

Here's the stack trace I receive:
> _crt_debugger_hook(_Reserved=4194304) Line 65 C
_invalid_parameter(pszExpression=0x00000000, pszFunction=0x00000000,
pszFile=0x00000000, nLine=0, pReserved=0) Line 86 + 0x7 bytes C++
_invalid_parameter_noinfo() Line 99 + 0xc bytes C++
std::basic_string<char,std::char_traits<char>,std::allocator<char>
>::erase(_First=0x05aaad98 "com.google.protobuf", _Last=0x05aaadab "")
Line 1265 + 0x24 bytes C++
std::basic_string<char,std::char_traits<char>,std::allocator<char>
>::clear() Line 1272 C++
google::protobuf::FileOptions::Clear() Line 3474 C++
google::protobuf::Message::ParseFromZeroCopyStream(input=0x0012ecec)
Line 139 + 0x9 bytes C++
google::protobuf::Message::ParseFromString(data="
com.google.protobufB DescriptorProtosH ") Line 151 C++

google::protobuf::DescriptorBuilder::OptionInterpreter::InterpretOptions
(options_to_interpret=0x05aaaf40) Line 3300 + 0xa bytes C++
google::protobuf::DescriptorBuilder::BuildFile(proto=,
descriptor_assigner=) Line 2405 + 0x15 bytes C++
google::protobuf::DescriptorPool::InternalBuildGeneratedFile
(data=0x049e3538, size=3449, descriptor_assigner=0x04985d90) Line 1962
+ 0x4d bytes C++

google::protobuf::protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto
() Line 547 C++
google::protobuf::DescriptorBuilder::CrossLinkMessage
(message=0x05a97a00, proto={...}) Line 2890 + 0xe bytes C++
google::protobuf::DescriptorBuilder::CrossLinkFile(file=0x00000000,
proto=) Line 2871 + 0x18 bytes C++
google::protobuf::DescriptorBuilder::BuildFile(proto={...},
descriptor_assigner=0x049563d0) Line 2400 C++
google::protobuf::DescriptorPool::InternalBuildGeneratedFile
(data=0x049dfd68, size=342, descriptor_assigner=0x049563d0) Line 1962
+ 0x4d bytes C++
fs::proto::protobuf_BuildDesc_arraydata_2eproto() Line 68 C++

Kenton Varda

unread,
Feb 3, 2009, 8:40:43 PM2/3/09
to fedor.l...@gmail.com, Protocol Buffers
Was libprotobuf.lib compiled in the same mode (debug vs. release) and with the same version of MSVC as your project?  If not, it could be a binary compatibility issue between the various versions of the CRT that MSVC uses in different modes.

Otherwise I don't have any ideas.

fedor.l...@gmail.com

unread,
Feb 3, 2009, 11:05:03 PM2/3/09
to Protocol Buffers
> Was libprotobuf.lib compiled in the same mode (debug vs. release) and with
> the same version of MSVC as your project? If not, it could be a binary
> compatibility issue between the various versions of the CRT that MSVC uses
> in different modes.

Unfortunately it was. I've been double and triple checking that as I
go seeing as that seems to be the number one culprit of protobuf
release mode crashes. We use other std classes in our project with no
apparent problems, including vector, string, and cout from iostream.
Thanks for the suggestion though.

Fedor
Reply all
Reply to author
Forward
0 new messages