[Android Interop]: Extend host_port lifespan (#32654)

Make sure a pointer to the buffer allocated on stack does not outlive
the stack frame.
pull/32643/head
Eugene Ostroukhov 2 years ago committed by GitHub
parent bf1a26cde8
commit 39e5e916d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/android/test/interop/app/src/main/cpp/grpc-interop.cc

@ -16,30 +16,30 @@
*
*/
#include <grpcpp/grpcpp.h>
#include <jni.h>
#include "absl/strings/str_format.h"
#include <grpcpp/grpcpp.h>
#include "src/core/lib/security/security_connector/ssl_utils_config.h"
#include "test/cpp/interop/interop_client.h"
std::shared_ptr<grpc::testing::InteropClient> GetClient(const char* host,
int port,
bool use_tls) {
const int host_port_buf_size = 1024;
char host_port[host_port_buf_size];
snprintf(host_port, host_port_buf_size, "%s:%d", host, port);
std::shared_ptr<grpc::ChannelCredentials> credentials;
if (use_tls) {
credentials = grpc::SslCredentials(grpc::SslCredentialsOptions());
} else {
credentials = grpc::InsecureChannelCredentials();
}
grpc::testing::ChannelCreationFunc channel_creation_func =
std::bind(grpc::CreateChannel, host_port, credentials);
return std::shared_ptr<grpc::testing::InteropClient>(
new grpc::testing::InteropClient(channel_creation_func, true, false));
std::string host_port = absl::StrFormat("%s:%d", host, port);
return std::make_shared<grpc::testing::InteropClient>(
[host_port, credentials](grpc::ChannelArguments args) {
return grpc::CreateCustomChannel(host_port, credentials, args);
},
true, false);
}
extern "C" JNIEXPORT jboolean JNICALL

Loading…
Cancel
Save