Fix memory leak in rpc ServerCall and ClientCall (#5046)

This commit is contained in:
Hao Chen
2019-06-27 13:19:47 +08:00
committed by GitHub
parent 49c6e81de2
commit 469ae41013
3 changed files with 6 additions and 2 deletions
+3 -1
View File
@@ -30,6 +30,8 @@ class ClientCall {
/// The callback to be called by `ClientCallManager` when the reply of this request is
/// received.
virtual void OnReplyReceived() = 0;
virtual ~ClientCall() = default;
};
class ClientCallManager;
@@ -142,7 +144,7 @@ class ClientCallManager {
bool ok = false;
// Keep reading events from the `CompletionQueue` until it's shutdown.
while (cq_.Next(&got_tag, &ok)) {
ClientCall *call = reinterpret_cast<ClientCall *>(got_tag);
auto *call = reinterpret_cast<ClientCall *>(got_tag);
if (ok) {
// Post the callback to the main event loop.
main_service_.post([call]() {
+1 -1
View File
@@ -43,7 +43,7 @@ void GrpcServer::PollEventsFromCompletionQueue() {
bool ok;
// Keep reading events from the `CompletionQueue` until it's shutdown.
while (cq_->Next(&tag, &ok)) {
ServerCall *server_call = static_cast<ServerCall *>(tag);
auto *server_call = static_cast<ServerCall *>(tag);
// `ok == false` indicates that the server has been shut down.
// We should delete the call object in this case.
bool delete_call = !ok;
+2
View File
@@ -58,6 +58,8 @@ class ServerCall {
/// Get the factory that created this `ServerCall`.
virtual const ServerCallFactory &GetFactory() const = 0;
virtual ~ServerCall() = default;
};
/// The factory that creates a particular kind of `ServerCall` objects.