Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init order for the dynamic_init_dummy in the generated code and fixed_address_empty_string is unpredictable #9289

Closed
jinghli opened this issue Dec 7, 2021 · 4 comments

Comments

@jinghli
Copy link

jinghli commented Dec 7, 2021

What version of protobuf and what language are you using?
Version: 3.17.3
Language: C++

What operating system (Linux, Windows, ...) and version?
Windows
What runtime / compiler are you using (e.g., python version or gcc version)
MSVC140
What did you do?
Link protobuf lib to my application. I saw 8 byte memory leak in runtime coming from protobuf.

We had a very simple proto file in the production code, the structure looks like this

syntax="proto2";

message test
{
    optional uint32 Version = 1 [default = 1];
	optional uint64 id = 2;
}

There is a global static var in the generated code

// Force running AddDescriptors() at dynamic initialization time.
PROTOBUF_ATTRIBUTE_INIT_PRIORITY static ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptorsRunner dynamic_init_dummy_test_2eproto(&descriptor_table_test_2eproto);

During the initialization, I can see dynamic_init_dummy_test_2eproto initialization actually zero-out fixed_address_empty_string in generated_message_util.cc(line 70). It eventually causes the shutdown process won't clean up memory completely. We think it is caused by the unpredictable init order for those two variables.

What did you expect to see
Expect no memory leak
What did you see instead?
Leak 8 bytes
Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment

@jinghli jinghli changed the title Init order for the dynamic_init_dummy in the generated code and fixed_address_empty_string are unpredictable Init order for the dynamic_init_dummy in the generated code and fixed_address_empty_string is unpredictable Dec 7, 2021
@elharo
Copy link
Contributor

elharo commented Dec 8, 2021

Thanks. We probably need a full reproducible test case to investigate this.

@jinghli
Copy link
Author

jinghli commented Dec 9, 2021

Thanks for following up. Totally understand. I'd need a bit time to craft the code to re-pro this issue without our business logic.

@snnn
Copy link
Contributor

snnn commented May 3, 2022

It looks very similar to #8129.

@deannagarcia
Copy link
Member

Closing because of no reproduction case, feel free to open it back up if you have one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants