Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1345)

Issue 7918: Fix protobuf static memory leak

Can't Edit
Can't Publish+Mail
Start Review
Created:
15 years, 5 months ago by Steven Mueller
Modified:
14 years, 9 months ago
Reviewers:
kenton
Base URL:
http://protobuf.googlecode.com/svn/trunk/src/
Visibility:
Public.

Description

protobuf - fix memory leak of statically initialized generated descriptor objects (C++) The reflection_ and default_instance_ objects allocated in the BuildDescriptors functions at static initialization time are not destructed prior to process teardown. This causes memory leak checkers (such as the one in MSVC) to complain. This change fixes the issue by making protoc also generate a destructor that deletes these objects. (Only the message objects actually have anything to destruct, but I've added placeholders for enums and services to help encourage cleanup of these if required in the future.) See http://code.google.com/p/protobuf/issues/detail?id=54 Tested with MSVC 8.0. All tests pass.

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+134 lines, -1 line) Patch
M google/protobuf/compiler/cpp/cpp_enum.h View 1 chunk +4 lines, -0 lines 0 comments Download
M google/protobuf/compiler/cpp/cpp_enum.cc View 1 chunk +6 lines, -0 lines 1 comment Download
M google/protobuf/compiler/cpp/cpp_file.cc View 3 chunks +26 lines, -0 lines 1 comment Download
M google/protobuf/compiler/cpp/cpp_message.h View 1 chunk +4 lines, -0 lines 1 comment Download
M google/protobuf/compiler/cpp/cpp_message.cc View 3 chunks +24 lines, -1 line 1 comment Download
M google/protobuf/compiler/cpp/cpp_service.h View 1 chunk +4 lines, -0 lines 0 comments Download
M google/protobuf/compiler/cpp/cpp_service.cc View 1 chunk +6 lines, -0 lines 1 comment Download
M google/protobuf/descriptor.pb.h View 18 chunks +18 lines, -0 lines 0 comments Download
M google/protobuf/descriptor.pb.cc View 1 chunk +42 lines, -0 lines 0 comments Download

Messages

Total messages: 1
kenton
15 years, 5 months ago (2008-11-04 02:52:13 UTC) #1
Mostly looks good.  I think you should just remove the empty methods.

I guess there is no good way to add a test case for this?

You will also need to sign the Contributor License Agreement before we can
accept this patch.

http://code.google.com/legal/individual-cla-v1.0.html -- if you own the
copyright on this work.
http://code.google.com/legal/corporate-cla-v1.0.html -- if your employer owns
it.

Thanks!

http://codereview.appspot.com/7918/diff/1/5
File google/protobuf/compiler/cpp/cpp_enum.cc (right):

http://codereview.appspot.com/7918/diff/1/5#newcode149
Line 149: // Nothing to do here
Then why define this method at all?

http://codereview.appspot.com/7918/diff/1/7
File google/protobuf/compiler/cpp/cpp_file.cc (right):

http://codereview.appspot.com/7918/diff/1/7#newcode330
Line 330: map<string, string> vars;
This doesn't appear to be used.

http://codereview.appspot.com/7918/diff/1/8
File google/protobuf/compiler/cpp/cpp_message.cc (right):

http://codereview.appspot.com/7918/diff/1/8#newcode510
Line 510: "friend void protobuf_DestroyDesc_$filename$();\n");
I'd name this $builddescriptorsname$_TearDown() instead for consistency.  (And
then you don't have to add a new variable to vars.)

http://codereview.appspot.com/7918/diff/1/9
File google/protobuf/compiler/cpp/cpp_message.h (right):

http://codereview.appspot.com/7918/diff/1/9#newcode94
Line 94: void GenerateDescriptorDestructor(io::Printer* printer);
The code that this method generates doesn't actually destroy the descriptor.  It
destroys the default instance and reflection objects.  Perhaps
"GenerateTearDown()" would be a better name?

http://codereview.appspot.com/7918/diff/1/3
File google/protobuf/compiler/cpp/cpp_service.cc (right):

http://codereview.appspot.com/7918/diff/1/3#newcode174
Line 174: // Nothing to do here
Then why define this method at all?
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b