From 146070db8db189a62112ae0b84de5d12ffc02f3a Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Fri, 18 Mar 2016 15:53:28 -0700 Subject: [PATCH] fixed multiple initialization of globals --- include/grpc++/impl/grpc_library.h | 8 ++++++-- src/cpp/client/secure_credentials.cc | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/grpc++/impl/grpc_library.h b/include/grpc++/impl/grpc_library.h index d26f4a4cab3..ecb5a4d64d2 100644 --- a/include/grpc++/impl/grpc_library.h +++ b/include/grpc++/impl/grpc_library.h @@ -58,8 +58,12 @@ static CoreCodegen g_core_codegen; class GrpcLibraryInitializer GRPC_FINAL { public: GrpcLibraryInitializer() { - grpc::g_glip = &g_gli; - grpc::g_core_codegen_interface = &g_core_codegen; + if (grpc::g_glip == nullptr) { + grpc::g_glip = &g_gli; + } + if (grpc::g_core_codegen_interface == nullptr) { + grpc::g_core_codegen_interface = &g_core_codegen; + } } /// A no-op method to force the linker to reference this class, which will diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 308455527c3..c34b840f908 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -60,8 +60,7 @@ std::shared_ptr SecureChannelCredentials::CreateChannel( SecureCallCredentials::SecureCallCredentials(grpc_call_credentials* c_creds) : c_creds_(c_creds) { - internal::GrpcLibraryInitializer gli_initializer; - gli_initializer.summon(); + g_gli_initializer.summon(); } bool SecureCallCredentials::ApplyToCall(grpc_call* call) {