Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Commit

Permalink
Fix stratum timer memory leak (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-m-cyr authored and chfast committed Jan 7, 2018
1 parent 3dc378f commit 37b1de2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
18 changes: 5 additions & 13 deletions libstratum/EthStratumClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ static void diffToTarget(uint32_t *target, double diff)


EthStratumClient::EthStratumClient(Farm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email)
: m_socket(m_io_service)
: m_socket(m_io_service),
m_worktimer(m_io_service)
{
m_minerType = m;
m_primary.host = host;
Expand All @@ -50,7 +51,6 @@ EthStratumClient::EthStratumClient(Farm* f, MinerType m, string const & host, st
m_submit_hashrate_id = h256::random().hex();

p_farm = f;
p_worktimer = nullptr;
connect();
}

Expand Down Expand Up @@ -100,10 +100,7 @@ void EthStratumClient::connect()

void EthStratumClient::reconnect()
{
if (p_worktimer) {
p_worktimer->cancel();
p_worktimer = nullptr;
}
m_worktimer.cancel();

m_io_service.reset();
//m_socket.close(); // leads to crashes on Linux
Expand Down Expand Up @@ -427,13 +424,12 @@ void EthStratumClient::processReponse(Json::Value& responseObject)

if (sHeaderHash != "" && sSeedHash != "" && sShareTarget != "")
{

h256 headerHash = h256(sHeaderHash);

if (headerHash != m_current.header)
{
if (p_worktimer)
p_worktimer->cancel();
m_worktimer.cancel();
m_worktimer.expires_from_now(boost::posix_time::seconds(m_worktimeout));

m_current.header = h256(sHeaderHash);
m_current.seed = h256(sSeedHash);
Expand All @@ -444,10 +440,6 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
cnote << "Received new job #" + job.substr(0, 8)
<< " seed: " << "#" + m_current.seed.hex().substr(0, 32)
<< " target: " << "#" + m_current.boundary.hex().substr(0, 24);

p_worktimer = new boost::asio::deadline_timer(m_io_service, boost::posix_time::seconds(m_worktimeout));
p_worktimer->async_wait(boost::bind(&EthStratumClient::work_timeout_handler, this, boost::asio::placeholders::error));

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion libstratum/EthStratumClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class EthStratumClient
boost::asio::streambuf m_requestBuffer;
boost::asio::streambuf m_responseBuffer;

boost::asio::deadline_timer * p_worktimer;
boost::asio::deadline_timer m_worktimer;

int m_protocol;
string m_email;
Expand Down

0 comments on commit 37b1de2

Please sign in to comment.