Issue 375 in protobuf: Invoking ShutdownProtobufLibrary() more than once causes segmentation fault.

499 views
Skip to first unread message

prot...@googlecode.com

unread,
Feb 16, 2012, 8:58:46 PM2/16/12
to prot...@googlegroups.com
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.

prot...@googlecode.com

unread,
Feb 16, 2012, 9:02:49 PM2/16/12
to prot...@googlegroups.com

Comment #1 on 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

Not sure if it matters, but I forgot to mention that I am statically
linking to it.

prot...@googlecode.com

unread,
Dec 5, 2012, 1:18:34 AM12/5/12
to prot...@googlegroups.com
Updates:
Status: Fixed
Labels: FixedIn-2.5.0

Comment #2 on issue 375 by liu...@google.com: Invoking
ShutdownProtobufLibrary() more than once causes segmentation fault.
http://code.google.com/p/protobuf/issues/detail?id=375

Fixed in r450

prot...@googlecode.com

unread,
Dec 5, 2012, 6:50:39 PM12/5/12
to prot...@googlegroups.com

Comment #3 on issue 375 by liu...@google.com: Invoking
ShutdownProtobufLibrary() more than once causes segmentation fault.
http://code.google.com/p/protobuf/issues/detail?id=375

Hmm, looks like the ShutdownProtoLibrary() already can be called by
multiple times. Rolled back r450.

Reply all
Reply to author
Forward
0 new messages