Added a line in build.yaml and starting to clean up memory leaks in unit tests

pull/19778/head
Matthew Stevenson 6 years ago
parent e8b28dd27b
commit 9da9c0786d
  1. 1
      build.yaml
  2. 5
      src/cpp/common/tls_credentials_options.cc
  3. 12
      test/cpp/client/credentials_test.cc

@ -506,6 +506,7 @@ filegroups:
- include/grpcpp/security/credentials_impl.h
- include/grpcpp/security/server_credentials.h
- include/grpcpp/security/server_credentials_impl.h
- include/grpcpp/security/tls_credentials_options.h
- include/grpcpp/server.h
- include/grpcpp/server_builder.h
- include/grpcpp/server_builder_impl.h

@ -31,7 +31,10 @@ void TlsKeyMaterialsConfig::set_key_materials(
pem_root_certs_ = std::move(pem_root_certs);
}
/** Creates a new C struct for the key materials. **/
/** Creates a new C struct for the key materials. Note that the user must free
* the underlying pointer to private key and cert chain duplicates; they are not
* freed when the UniquePtr<char> member variables of PemKeyCertPair are unused.
* Similarly, the user must free the underlying pointer to c_pem_root_certs. **/
grpc_tls_key_materials_config* c_key_materials(
const std::shared_ptr<TlsKeyMaterialsConfig>& config) {
grpc_tls_key_materials_config* c_config =

@ -286,6 +286,9 @@ TEST_F(CredentialsTest, TlsKeyMaterialsConfigCppToC) {
c_config->pem_key_cert_pair_list()[0].private_key());
EXPECT_STREQ(pair.cert_chain.c_str(),
c_config->pem_key_cert_pair_list()[0].cert_chain());
gpr_free(c_config->pem_key_cert_pair_list()[0].private_key());
gpr_free(c_config->pem_key_cert_pair_list()[0].cert_chain());
gpr_free(const_cast<char*>(c_config->pem_root_certs()));
gpr_free(c_config);
}
@ -411,6 +414,11 @@ TEST_F(CredentialsTest, TlsCredentialReloadConfigCppToC) {
c_config->Cancel(&c_arg);
EXPECT_EQ(c_arg.status, GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_FAIL);
EXPECT_STREQ(c_arg.error_details, "cancelled");
gpr_free(const_cast<char*>(ssl_pair->private_key));
gpr_free(const_cast<char*>(ssl_pair->cert_chain));
gpr_free(ssl_pair);
gpr_free(c_config);
}
typedef class ::grpc_impl::experimental::TlsServerAuthorizationCheckArg
@ -430,6 +438,7 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckArgCallback) {
TlsServerAuthorizationCheckArg arg(c_arg);
arg.callback();
EXPECT_STREQ(static_cast<char*>(arg.cb_user_data()), "cb_user_data");
gpr_free(arg.cb_user_data());
EXPECT_EQ(arg.success(), 1);
EXPECT_STREQ(arg.target_name()->c_str(), "callback_target_name");
EXPECT_STREQ(arg.peer_cert()->c_str(), "callback_peer_cert");
@ -450,6 +459,7 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigSchedule) {
int schedule_output = config.Schedule(&arg);
EXPECT_EQ(schedule_output, 1);
EXPECT_STREQ(static_cast<char*>(arg.cb_user_data()), "cb_user_data");
gpr_free(arg.cb_user_data());
EXPECT_EQ(arg.success(), 1);
EXPECT_STREQ(arg.target_name()->c_str(), "sync_target_name");
EXPECT_STREQ(arg.peer_cert()->c_str(), "sync_peer_cert");
@ -476,6 +486,7 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigCppToC) {
int c_schedule_output = c_config->Schedule(&c_arg);
EXPECT_EQ(c_schedule_output, 1);
EXPECT_STREQ(static_cast<char*>(c_arg.cb_user_data), "cb_user_data");
gpr_free(c_arg.cb_user_data);
EXPECT_EQ(c_arg.success, 1);
EXPECT_STREQ(c_arg.target_name, "sync_target_name");
EXPECT_STREQ(c_arg.peer_cert, "sync_peer_cert");
@ -575,6 +586,7 @@ TEST_F(CredentialsTest, TlsCredentialsOptionsCppToC) {
EXPECT_STREQ(
static_cast<char*>(c_server_authorization_check_arg.cb_user_data),
"cb_user_data");
gpr_free(c_server_authorization_check_arg.cb_user_data);
EXPECT_EQ(c_server_authorization_check_arg.success, 1);
EXPECT_STREQ(c_server_authorization_check_arg.target_name,
"sync_target_name");

Loading…
Cancel
Save