From 18f27376c531e857d8fb946d758c81880023ed42 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 31 Jan 2018 22:35:17 +0100 Subject: avoid touching stats_ instance field before base constructor --- test/cpp/performance/writes_per_rpc_test.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'test/cpp/performance') diff --git a/test/cpp/performance/writes_per_rpc_test.cc b/test/cpp/performance/writes_per_rpc_test.cc index 0866b58f58..86e3bbcd4e 100644 --- a/test/cpp/performance/writes_per_rpc_test.cc +++ b/test/cpp/performance/writes_per_rpc_test.cc @@ -142,25 +142,25 @@ class EndpointPairFixture { class InProcessCHTTP2 : public EndpointPairFixture { public: - InProcessCHTTP2(Service* service) - : EndpointPairFixture(service, MakeEndpoints()) {} + InProcessCHTTP2(Service* service, grpc_passthru_endpoint_stats* stats = + grpc_passthru_endpoint_stats_create()) + : EndpointPairFixture(service, MakeEndpoints(stats)), stats_(stats) {} - virtual ~InProcessCHTTP2() { grpc_passthru_endpoint_stats_destroy(stats_); } + virtual ~InProcessCHTTP2() { + if (stats_ != nullptr) { + grpc_passthru_endpoint_stats_destroy(stats_); + } + } int writes_performed() const { return stats_->num_writes; } private: grpc_passthru_endpoint_stats* stats_; - grpc_endpoint_pair MakeEndpoints() { - stats_ = grpc_passthru_endpoint_stats_create(); // is there a better way to - // initialize stats_ and - // pass MakeEndpoints's - // return value to base - // constructor? + static grpc_endpoint_pair MakeEndpoints(grpc_passthru_endpoint_stats* stats) { grpc_endpoint_pair p; grpc_passthru_endpoint_create(&p.client, &p.server, initialize_stuff.rq(), - stats_); + stats); return p; } }; -- cgit v1.2.3