Changed delete per Yang's comment.

pull/19778/head
Matthew Stevenson 5 years ago
parent 00cce90adf
commit ed198f5a54
  1. 6
      include/grpc/grpc_security.h
  2. 6
      src/core/lib/security/security_connector/tls/spiffe_security_connector.cc
  3. 2
      src/cpp/common/tls_credentials_options.cc
  4. 20
      src/cpp/common/tls_credentials_options_util.cc
  5. 9
      src/cpp/common/tls_credentials_options_util.h
  6. 27
      test/cpp/client/credentials_test.cc

@ -818,6 +818,8 @@ typedef void (*grpc_tls_on_credential_reload_done_cb)(
instance that this argument corresponds to.
- context is a pointer to a wrapped language implementation of this
grpc_tls_credential_reload_arg instance.
- destroy_context is a pointer to a caller-provided method that cleans
up any data associated with the context pointer.
It is used for experimental purposes for now and subject to change.
*/
struct grpc_tls_credential_reload_arg {
@ -828,6 +830,7 @@ struct grpc_tls_credential_reload_arg {
const char* error_details;
grpc_tls_credential_reload_config* config;
void* context;
void (*destroy_context)(void* ctx);
};
/** Create a grpc_tls_credential_reload_config instance.
@ -889,6 +892,8 @@ typedef void (*grpc_tls_on_server_authorization_check_done_cb)(
corresponds to.
- context is a pointer to a wrapped language implementation of this
grpc_tls_server_authorization_check_arg instance.
- destroy_context is a pointer to a caller-provided method that cleans
up any data associated with the context pointer.
It is used for experimental purpose for now and subject to change.
*/
struct grpc_tls_server_authorization_check_arg {
@ -901,6 +906,7 @@ struct grpc_tls_server_authorization_check_arg {
const char* error_details;
grpc_tls_server_authorization_check_config* config;
void* context;
void (*destroy_context)(void* ctx);
};
/** Create a grpc_tls_server_authorization_check_config instance.

@ -104,6 +104,9 @@ grpc_status_code TlsFetchKeyMaterials(
}
}
gpr_free((void*)arg->error_details);
if (arg->destroy_context != nullptr) {
arg->destroy_context(arg->context);
}
grpc_core::Delete(arg);
}
return status;
@ -392,6 +395,9 @@ void SpiffeChannelSecurityConnector::ServerAuthorizationCheckArgDestroy(
gpr_free((void*)arg->target_name);
gpr_free((void*)arg->peer_cert);
gpr_free((void*)arg->error_details);
if (arg->destroy_context != nullptr) {
arg->destroy_context(arg->context);
}
grpc_core::Delete(arg);
}

@ -51,6 +51,7 @@ TlsCredentialReloadArg::TlsCredentialReloadArg(
gpr_log(GPR_ERROR, "c_arg context has already been set");
}
c_arg_->context = static_cast<void*>(this);
c_arg_->destroy_context = &TlsCredentialReloadArgDestroyContext;
}
TlsCredentialReloadArg::~TlsCredentialReloadArg() {}
@ -166,6 +167,7 @@ TlsServerAuthorizationCheckArg::TlsServerAuthorizationCheckArg(
gpr_log(GPR_ERROR, "c_arg context has already been set");
}
c_arg_->context = static_cast<void*>(this);
c_arg_->destroy_context = &TlsServerAuthorizationCheckArgDestroyContext;
}
TlsServerAuthorizationCheckArg::~TlsServerAuthorizationCheckArg() {}

@ -70,7 +70,6 @@ int TlsCredentialReloadConfigCSchedule(void* config_user_data,
static_cast<TlsCredentialReloadConfig*>(arg->config->context());
TlsCredentialReloadArg* cpp_arg = new TlsCredentialReloadArg(arg);
int schedule_result = cpp_config->Schedule(cpp_arg);
delete cpp_arg;
return schedule_result;
}
@ -90,7 +89,14 @@ void TlsCredentialReloadConfigCCancel(void* config_user_data,
TlsCredentialReloadArg* cpp_arg =
static_cast<TlsCredentialReloadArg*>(arg->context);
cpp_config->Cancel(cpp_arg);
delete cpp_arg;
}
void TlsCredentialReloadArgDestroyContext(void* context) {
if (context != nullptr) {
TlsCredentialReloadArg* cpp_arg =
static_cast<TlsCredentialReloadArg*>(context);
delete cpp_arg;
}
}
/** The C schedule and cancel functions for the server authorization check
@ -109,7 +115,6 @@ int TlsServerAuthorizationCheckConfigCSchedule(
TlsServerAuthorizationCheckArg* cpp_arg =
new TlsServerAuthorizationCheckArg(arg);
int schedule_result = cpp_config->Schedule(cpp_arg);
delete cpp_arg;
return schedule_result;
}
@ -131,7 +136,14 @@ void TlsServerAuthorizationCheckConfigCCancel(
TlsServerAuthorizationCheckArg* cpp_arg =
static_cast<TlsServerAuthorizationCheckArg*>(arg->context);
cpp_config->Cancel(cpp_arg);
delete cpp_arg;
}
void TlsServerAuthorizationCheckArgDestroyContext(void* context) {
if (context != nullptr) {
TlsServerAuthorizationCheckArg* cpp_arg =
static_cast<TlsServerAuthorizationCheckArg*>(context);
delete cpp_arg;
}
}
} // namespace experimental

@ -33,8 +33,7 @@ grpc_tls_key_materials_config* ConvertToCKeyMaterialsConfig(
/** The following 4 functions convert the user-provided schedule or cancel
* functions into C style schedule or cancel functions. These are internal
* functions, not meant to be accessed by the user. They are exposed for
* testing purposes only. **/
* functions, not meant to be accessed by the user. **/
int TlsCredentialReloadConfigCSchedule(void* config_user_data,
grpc_tls_credential_reload_arg* arg);
@ -47,6 +46,12 @@ int TlsServerAuthorizationCheckConfigCSchedule(
void TlsServerAuthorizationCheckConfigCCancel(
void* config_user_data, grpc_tls_server_authorization_check_arg* arg);
/** The following 2 functions cleanup data created in the above C schedule
* functions. **/
void TlsCredentialReloadArgDestroyContext(void* context);
void TlsServerAuthorizationCheckArgDestroyContext(void* context);
} // namespace experimental
} // namespace grpc_impl

@ -316,6 +316,7 @@ typedef class ::grpc_impl::experimental::TlsCredentialReloadConfig
TEST_F(CredentialsTest, TlsCredentialReloadArgCallback) {
grpc_tls_credential_reload_arg* c_arg = new grpc_tls_credential_reload_arg;
c_arg->cb = tls_credential_reload_callback;
c_arg->context = nullptr;
TlsCredentialReloadArg* arg = new TlsCredentialReloadArg(c_arg);
arg->set_status(GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW);
arg->OnCredentialReloadDoneCallback();
@ -369,7 +370,10 @@ TEST_F(CredentialsTest, TlsCredentialReloadConfigSchedule) {
// Cleanup.
gpr_free(const_cast<char*>(error_details_before_schedule));
grpc_core::Delete(c_arg->key_materials_config);
delete arg;
// delete arg;
if (c_arg->destroy_context != nullptr) {
c_arg->destroy_context(c_arg->context);
}
gpr_free(c_arg);
gpr_free(config->c_config());
}
@ -422,6 +426,7 @@ TEST_F(CredentialsTest, TlsCredentialReloadConfigCppToC) {
c_arg.key_materials_config;
// Cleanup.
c_arg.destroy_context(c_arg.context);
::grpc_core::Delete(config.c_config());
}
@ -434,6 +439,7 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckArgCallback) {
grpc_tls_server_authorization_check_arg* c_arg =
new grpc_tls_server_authorization_check_arg;
c_arg->cb = tls_server_authorization_check_callback;
c_arg->context = nullptr;
TlsServerAuthorizationCheckArg* arg =
new TlsServerAuthorizationCheckArg(c_arg);
arg->set_cb_user_data(nullptr);
@ -501,7 +507,10 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigSchedule) {
gpr_free(const_cast<char*>(c_arg->target_name));
gpr_free(const_cast<char*>(c_arg->peer_cert));
gpr_free(const_cast<char*>(c_arg->error_details));
delete arg;
// delete arg;
if (c_arg->destroy_context != nullptr) {
c_arg->destroy_context(c_arg->context);
}
gpr_free(c_arg);
gpr_free(config.c_config());
}
@ -530,6 +539,7 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigCppToC) {
// Cleanup.
gpr_free(c_arg.cb_user_data);
c_arg.destroy_context(c_arg.context);
gpr_free(const_cast<char*>(c_arg.error_details));
gpr_free(const_cast<char*>(c_arg.target_name));
gpr_free(const_cast<char*>(c_arg.peer_cert));
@ -632,6 +642,9 @@ TEST_F(CredentialsTest, TlsCredentialsOptionsCppToC) {
// Cleanup.
::grpc_core::Delete(c_credential_reload_arg.key_materials_config);
c_credential_reload_arg.destroy_context(c_credential_reload_arg.context);
c_server_authorization_check_arg.destroy_context(
c_server_authorization_check_arg.context);
gpr_free(c_server_authorization_check_arg.cb_user_data);
gpr_free(const_cast<char*>(c_server_authorization_check_arg.target_name));
gpr_free(const_cast<char*>(c_server_authorization_check_arg.peer_cert));
@ -683,7 +696,10 @@ TEST_F(CredentialsTest, TlsCredentialReloadConfigErrorMessages) {
// Cleanup.
gpr_free(const_cast<char*>(c_arg->error_details));
delete arg;
// delete arg;
if (c_arg->destroy_context != nullptr) {
c_arg->destroy_context(c_arg->context);
}
delete c_arg;
gpr_free(config->c_config());
}
@ -713,7 +729,10 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigErrorMessages) {
// Cleanup.
gpr_free(const_cast<char*>(c_arg->error_details));
delete arg;
// delete arg;
if (c_arg->destroy_context != nullptr) {
c_arg->destroy_context(c_arg->context);
}
delete c_arg;
gpr_free(config->c_config());
}

Loading…
Cancel
Save