Fix memory corruption

pull/8503/head
Craig Tiller 8 years ago
parent b4d883bfc2
commit ff8e43aa6c
  1. 21
      test/cpp/microbenchmarks/bm_fullstack.cc

@ -226,7 +226,7 @@ static void* tag(intptr_t x) { return reinterpret_cast<void*>(x); }
template <class Fixture> template <class Fixture>
static void BM_UnaryPingPong(benchmark::State& state) { static void BM_UnaryPingPong(benchmark::State& state) {
EchoTestService::AsyncService service; EchoTestService::AsyncService service;
Fixture fixture(&service); std::unique_ptr<Fixture> fixture(new Fixture(&service));
EchoRequest send_request; EchoRequest send_request;
EchoResponse send_response; EchoResponse send_response;
EchoResponse recv_response; EchoResponse recv_response;
@ -244,20 +244,20 @@ static void BM_UnaryPingPong(benchmark::State& state) {
new (server_env[0]) ServerEnv; new (server_env[0]) ServerEnv;
new (server_env[1]) ServerEnv; new (server_env[1]) ServerEnv;
service.RequestEcho(&server_env[0]->ctx, &server_env[0]->recv_request, service.RequestEcho(&server_env[0]->ctx, &server_env[0]->recv_request,
&server_env[0]->response_writer, fixture.cq(), &server_env[0]->response_writer, fixture->cq(),
fixture.cq(), tag(0)); fixture->cq(), tag(0));
service.RequestEcho(&server_env[1]->ctx, &server_env[1]->recv_request, service.RequestEcho(&server_env[1]->ctx, &server_env[1]->recv_request,
&server_env[1]->response_writer, fixture.cq(), &server_env[1]->response_writer, fixture->cq(),
fixture.cq(), tag(1)); fixture->cq(), tag(1));
std::unique_ptr<EchoTestService::Stub> stub( std::unique_ptr<EchoTestService::Stub> stub(
EchoTestService::NewStub(fixture.channel())); EchoTestService::NewStub(fixture->channel()));
while (state.KeepRunning()) { while (state.KeepRunning()) {
ClientContext cli_ctx; ClientContext cli_ctx;
std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader( std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
stub->AsyncEcho(&cli_ctx, send_request, fixture.cq())); stub->AsyncEcho(&cli_ctx, send_request, fixture->cq()));
void* t; void* t;
bool ok; bool ok;
GPR_ASSERT(fixture.cq()->Next(&t, &ok)); GPR_ASSERT(fixture->cq()->Next(&t, &ok));
GPR_ASSERT(ok); GPR_ASSERT(ok);
GPR_ASSERT(t == tag(0) || t == tag(1)); GPR_ASSERT(t == tag(0) || t == tag(1));
intptr_t slot = reinterpret_cast<intptr_t>(t); intptr_t slot = reinterpret_cast<intptr_t>(t);
@ -265,7 +265,7 @@ static void BM_UnaryPingPong(benchmark::State& state) {
senv->response_writer.Finish(send_response, Status::OK, tag(3)); senv->response_writer.Finish(send_response, Status::OK, tag(3));
response_reader->Finish(&recv_response, &recv_status, tag(4)); response_reader->Finish(&recv_response, &recv_status, tag(4));
for (int i = (1 << 3) | (1 << 4); i != 0;) { for (int i = (1 << 3) | (1 << 4); i != 0;) {
GPR_ASSERT(fixture.cq()->Next(&t, &ok)); GPR_ASSERT(fixture->cq()->Next(&t, &ok));
GPR_ASSERT(ok); GPR_ASSERT(ok);
int tagnum = (int)reinterpret_cast<intptr_t>(t); int tagnum = (int)reinterpret_cast<intptr_t>(t);
GPR_ASSERT(i & (1 << tagnum)); GPR_ASSERT(i & (1 << tagnum));
@ -276,8 +276,9 @@ static void BM_UnaryPingPong(benchmark::State& state) {
senv->~ServerEnv(); senv->~ServerEnv();
senv = new (senv) ServerEnv(); senv = new (senv) ServerEnv();
service.RequestEcho(&senv->ctx, &senv->recv_request, &senv->response_writer, service.RequestEcho(&senv->ctx, &senv->recv_request, &senv->response_writer,
fixture.cq(), fixture.cq(), tag(slot)); fixture->cq(), fixture->cq(), tag(slot));
} }
fixture.reset();
server_env[0]->~ServerEnv(); server_env[0]->~ServerEnv();
server_env[1]->~ServerEnv(); server_env[1]->~ServerEnv();
} }

Loading…
Cancel
Save