Status: New
Owner: liuj...@google.com
Labels: Type-Defect Priority-Medium
New issue 375 by jon.sale...@gmail.com: Invoking ShutdownProtobufLibrary()
more than once causes segmentation fault.
http://code.google.com/p/protobuf/issues/detail?id=375
Configuration:
- Protobuf 2.3.0
- GCC 4.4.4 Linux 64-bit
The documentation states:
// Shut down the entire protocol buffers library, deleting all
static-duration
// objects allocated by the library or by generated .pb.cc files.
//
// There are two reasons you might want to call this:
// * You use a draconian definition of "memory leak" in which you expect
// every single malloc() to have a corresponding free(), even for objects
// which live until program exit.
// * You are writing a dynamically-loaded library which needs to clean up
// after itself when the library is unloaded.
//
// It is safe to call this multiple times. However, it is not safe to use
// any other part of the protocol buffers library after
// ShutdownProtobufLibrary() has been called.
LIBPROTOBUF_EXPORT void ShutdownProtobufLibrary();
However, if you look at the generated code that gets invoked on shutdown,
void protobuf_ShutdownFile_XXXXXX_2eproto() {
delete GlobalContext::default_instance_;
delete FileContext::default_instance_;
}
it looks like it can cause a double-free (which it does for me) if
ShutdownProtobufLibrary is invoked more than once since ::default_instance_
is not set to safe value on delete. Something like
void protobuf_ShutdownFile_XXXXXX_2eproto() {
delete GlobalContext::default_instance_;
GlobalContext::default_instance_ = NULL;
delete FileContext::default_instance_;
FileContext::default_instance_ = NULL;
}
would be more robust and prevent the double-free case.
-----------------
What steps will reproduce the problem?
1. create a .proto file.
2. use protoc.exe to generate an implementation (pb.cc).
3. create a sample program that invokes ShutdownProtobugLibrary(...) more
than one time.
--
You received this message because you are subscribed to the Google Groups "Protocol
Buffers" group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.