aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2015-06-02 13:28:46 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2015-06-02 13:41:48 -0700
commitc9516d4e28b2742b8953efaff4252e1346115723 (patch)
tree6751fceeb28ef10f4ceab19747e78c9861987bb3 /test/cpp
parent206e6e844140a3a477d65767d4a92e19d9893e56 (diff)
Fixed memory leak in server_async
Diffstat (limited to 'test/cpp')
-rw-r--r--test/cpp/qps/server_async.cc33
1 files changed, 18 insertions, 15 deletions
diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc
index b9998405f6..977dfc2372 100644
--- a/test/cpp/qps/server_async.cc
+++ b/test/cpp/qps/server_async.cc
@@ -33,6 +33,7 @@
#include <forward_list>
#include <functional>
+#include <memory>
#include <mutex>
#include <sys/time.h>
#include <sys/resource.h>
@@ -158,11 +159,12 @@ class AsyncQpsServerTest : public Server {
void *)> request_method,
std::function<grpc::Status(const RequestType *, ResponseType *)>
invoke_method)
- : next_state_(&ServerRpcContextUnaryImpl::invoker),
+ : srv_ctx_(new ServerContext),
+ next_state_(&ServerRpcContextUnaryImpl::invoker),
request_method_(request_method),
invoke_method_(invoke_method),
- response_writer_(&srv_ctx_) {
- request_method_(&srv_ctx_, &req_, &response_writer_,
+ response_writer_(srv_ctx_.get()) {
+ request_method_(srv_ctx_.get(), &req_, &response_writer_,
AsyncQpsServerTest::tag(this));
}
~ServerRpcContextUnaryImpl() GRPC_OVERRIDE {}
@@ -170,14 +172,14 @@ class AsyncQpsServerTest : public Server {
return (this->*next_state_)(ok);
}
void Reset() GRPC_OVERRIDE {
- srv_ctx_ = ServerContext();
+ srv_ctx_.reset(new ServerContext);
req_ = RequestType();
response_writer_ =
- grpc::ServerAsyncResponseWriter<ResponseType>(&srv_ctx_);
+ grpc::ServerAsyncResponseWriter<ResponseType>(srv_ctx_.get());
// Then request the method
next_state_ = &ServerRpcContextUnaryImpl::invoker;
- request_method_(&srv_ctx_, &req_, &response_writer_,
+ request_method_(srv_ctx_.get(), &req_, &response_writer_,
AsyncQpsServerTest::tag(this));
}
@@ -198,7 +200,7 @@ class AsyncQpsServerTest : public Server {
response_writer_.Finish(response, status, AsyncQpsServerTest::tag(this));
return true;
}
- ServerContext srv_ctx_;
+ std::unique_ptr<ServerContext> srv_ctx_;
RequestType req_;
bool (ServerRpcContextUnaryImpl::*next_state_)(bool);
std::function<void(ServerContext *, RequestType *,
@@ -218,25 +220,26 @@ class AsyncQpsServerTest : public Server {
void *)> request_method,
std::function<grpc::Status(const RequestType *, ResponseType *)>
invoke_method)
- : next_state_(&ServerRpcContextStreamingImpl::request_done),
+ : srv_ctx_(new ServerContext),
+ next_state_(&ServerRpcContextStreamingImpl::request_done),
request_method_(request_method),
invoke_method_(invoke_method),
- stream_(&srv_ctx_) {
- request_method_(&srv_ctx_, &stream_, AsyncQpsServerTest::tag(this));
+ stream_(srv_ctx_.get()) {
+ request_method_(srv_ctx_.get(), &stream_, AsyncQpsServerTest::tag(this));
}
~ServerRpcContextStreamingImpl() GRPC_OVERRIDE {}
bool RunNextState(bool ok) GRPC_OVERRIDE {
return (this->*next_state_)(ok);
}
void Reset() GRPC_OVERRIDE {
- srv_ctx_ = ServerContext();
+ srv_ctx_.reset(new ServerContext);
req_ = RequestType();
- stream_ =
- grpc::ServerAsyncReaderWriter<ResponseType, RequestType>(&srv_ctx_);
+ stream_ = grpc::ServerAsyncReaderWriter<ResponseType, RequestType>(
+ srv_ctx_.get());
// Then request the method
next_state_ = &ServerRpcContextStreamingImpl::request_done;
- request_method_(&srv_ctx_, &stream_, AsyncQpsServerTest::tag(this));
+ request_method_(srv_ctx_.get(), &stream_, AsyncQpsServerTest::tag(this));
}
private:
@@ -278,7 +281,7 @@ class AsyncQpsServerTest : public Server {
}
bool finish_done(bool ok) { return false; /* reset the context */ }
- ServerContext srv_ctx_;
+ std::unique_ptr<ServerContext> srv_ctx_;
RequestType req_;
bool (ServerRpcContextStreamingImpl::*next_state_)(bool);
std::function<void(