aboutsummaryrefslogtreecommitdiff
path: root/src/torcontrol.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-03-11 08:18:06 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2016-03-11 08:19:55 +0100
commit3da5d1bc2e5d9418ba236f8b4cab24204debbd9f (patch)
tree95c7172048a090de0ec397a3e4e0558708f88d7b /src/torcontrol.cpp
parentc8d2473e6cb042e7275a10c49d3f6a4a91bf0166 (diff)
parente2195037116f47b11b66452351dba4fe606423a2 (diff)
Merge #7637: Fix memleak in TorController [rework]
e219503 Fix memleak in TorController [rework] (Wladimir J. van der Laan)
Diffstat (limited to 'src/torcontrol.cpp')
-rw-r--r--src/torcontrol.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp
index 10170dbcea..a04b5c3024 100644
--- a/src/torcontrol.cpp
+++ b/src/torcontrol.cpp
@@ -398,6 +398,9 @@ TorController::TorController(struct event_base* base, const std::string& target)
target(target), conn(base), reconnect(true), reconnect_ev(0),
reconnect_timeout(RECONNECT_TIMEOUT_START)
{
+ reconnect_ev = event_new(base, -1, 0, reconnect_cb, this);
+ if (!reconnect_ev)
+ LogPrintf("tor: Failed to create event for reconnection: out of memory?\n");
// Start connection attempts immediately
if (!conn.Connect(target, boost::bind(&TorController::connected_cb, this, _1),
boost::bind(&TorController::disconnected_cb, this, _1) )) {
@@ -413,8 +416,10 @@ TorController::TorController(struct event_base* base, const std::string& target)
TorController::~TorController()
{
- if (reconnect_ev)
- event_del(reconnect_ev);
+ if (reconnect_ev) {
+ event_free(reconnect_ev);
+ reconnect_ev = 0;
+ }
if (service.IsValid()) {
RemoveLocal(service);
}
@@ -626,8 +631,8 @@ void TorController::disconnected_cb(TorControlConnection& conn)
// Single-shot timer for reconnect. Use exponential backoff.
struct timeval time = MillisToTimeval(int64_t(reconnect_timeout * 1000.0));
- reconnect_ev = event_new(base, -1, 0, reconnect_cb, this);
- event_add(reconnect_ev, &time);
+ if (reconnect_ev)
+ event_add(reconnect_ev, &time);
reconnect_timeout *= RECONNECT_TIMEOUT_EXP;
}