Skip to content

Commit a52e56e

Browse files
committed
always addTimerCallback for avoid memory leak when pass NULL cbw and not response.
1 parent 1e69ebc commit a52e56e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/transport/TcpRemotingClient.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,12 @@ bool TcpRemotingClient::invokeAsync(const string& addr,
242242
responseFuture->setRequestCommand(request);
243243
addResponseFuture(opaque, responseFuture);
244244

245-
if (callback) {
246-
boost::asio::deadline_timer* t =
247-
new boost::asio::deadline_timer(m_timerService, boost::posix_time::milliseconds(timeoutMillis));
248-
addTimerCallback(t, opaque);
249-
t->async_wait(
250-
boost::bind(&TcpRemotingClient::handleAsyncRequestTimeout, this, boost::asio::placeholders::error, opaque));
251-
}
245+
// timeout monitor
246+
boost::asio::deadline_timer* t =
247+
new boost::asio::deadline_timer(m_timerService, boost::posix_time::milliseconds(timeoutMillis));
248+
addTimerCallback(t, opaque);
249+
t->async_wait(
250+
boost::bind(&TcpRemotingClient::handleAsyncRequestTimeout, this, boost::asio::placeholders::error, opaque));
252251

253252
// even if send failed, asyncTimerThread will trigger next pull request or report send msg failed
254253
if (SendCommand(pTcp, request)) {

0 commit comments

Comments
 (0)