Issue 444 in protobuf: ShutdownProtobufLibrary() have to be called from each binaries, not only once.

723 views
Skip to first unread message

prot...@googlecode.com

unread,
Dec 18, 2012, 10:58:34 AM12/18/12
to prot...@googlegroups.com
Status: New
Owner: liu...@google.com
Labels: Type-Defect Priority-Medium

New issue 444 by mjk...@gmail.com: ShutdownProtobufLibrary() have to be
called from each binaries, not only once.
http://code.google.com/p/protobuf/issues/detail?id=444

I'm using Visual Studio 2012 Update 1.
I also use VLD to check memory leaks (which is far more helpful than the VS
basic memory leak feature).

Assuming you have an application with several binaries, memory leaks occurs
if ShutdownProtobufLibrary() is not called from code in each of the
binaries using protobuf (in static lib), not only from the main executable.

Let's say I have
- Foo : an executable using protobuf statically linked;
- Bar : a DLL using protobuf statically linked;
- Foo is linking Bar at compilation.
- Both Foo and Bar use protoc generated source code and libprotobuf
serialization functions.

Then I observe that:
- If ShutdownProtobufLibrary() is called only at the end of main() in
Foor, VLD will report memory leaks from protobuf.
- If ShutdownProtobufLibrary() is called only somewhere in Bar (making
sure it's called after use but before the end of main()), then I also have
VLD reporting memory leaks from protobuf.
- If I have both Foo calling ShutdownProtobufLibrary() and Bar calling it
once not used but before Foo's call, then VLD report no memory leaks.

There should be a way to have a clean shutdown from only one point (at the
end of the main() function). Maybe through another more general function?


prot...@googlecode.com

unread,
Dec 18, 2012, 3:22:18 PM12/18/12
to prot...@googlegroups.com
Updates:
Status: WorkingAsIntended
Cc: xiaof...@google.com

Comment #1 on issue 444 by liu...@google.com: ShutdownProtobufLibrary()
have to be called from each binaries, not only once.
http://code.google.com/p/protobuf/issues/detail?id=444

I think static link another library to a dynamic library is quite platform
dependent. From the behavior you noted, it seemed that the dll just linked
the code but did not export any symbols; all the global variables defined
in the protobuf library were duplicated.

I don't see a way to have a general function for the shutdown, because the
libprotobuf is not exported in the dll. The only way is to propagate the
shut down function (export another function which is delegated to the
protobuf shutdown) in the dll. You can then call the exported function
before your main exits.

Or maybe just do not static the protobuf library in the dll.

prot...@googlecode.com

unread,
Jan 1, 2013, 11:56:37 AM1/1/13
to prot...@googlegroups.com

Comment #2 on issue 444 by mjk...@gmail.com: ShutdownProtobufLibrary()
have to be called from each binaries, not only once.
http://code.google.com/p/protobuf/issues/detail?id=444

Unfortunately, protobuf not supporting CMake makes difficult to maintain
upgrading it when you use the dll library because Visual Studio have to be
open to change the linking type.

Using the dll version of the protobuf library would have been perfect to me
but because of this lack of CMake support it is not a real option at the
moment.

prot...@googlecode.com

unread,
Jan 1, 2013, 11:57:47 AM1/1/13
to prot...@googlegroups.com

Comment #3 on issue 444 by mjk...@gmail.com: ShutdownProtobufLibrary()
have to be called from each binaries, not only once.
http://code.google.com/p/protobuf/issues/detail?id=444

(sorry I forgot to say why):

...because the default config of protobuf project files for all platforms
is to compile in static mode (for the reasons provided in the readme file).


Reply all
Reply to author
Forward
0 new messages