summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-01-21 08:43:00 (GMT)
committerTobias Markmann <tm@ayena.de>2016-01-21 09:34:29 (GMT)
commitf377207cb896679b4eab9f6773d9d071700852ad (patch)
treeec31fa8a6feb3512c4d86c750a1eb5fb45fd75ef
parent0ca3ea9a88acb5e2d42baa3a85d61495d72b7352 (diff)
downloadswift-f377207cb896679b4eab9f6773d9d071700852ad.zip
swift-f377207cb896679b4eab9f6773d9d071700852ad.tar.bz2
Stop timer during clean up of WhitespacePingLayer
AddressSanitizer reported a heap-buffer-overflow in WhitespacePingLayer::handleTimerTick() which happened during multiple restarts of a XMPP server. Under the assumption that it was caused by not correctly stopping the timer, the timer is now explicitly stopped if still active at destruction. Test-Information: Unable to reproduce the ASAN report. Unit tests still pass. Change-Id: Ia0b7c3b613688750c4ce0ad40d759a0db4a52791
-rw-r--r--Swiften/StreamStack/WhitespacePingLayer.cpp13
-rw-r--r--Swiften/StreamStack/WhitespacePingLayer.h3
2 files changed, 13 insertions, 3 deletions
diff --git a/Swiften/StreamStack/WhitespacePingLayer.cpp b/Swiften/StreamStack/WhitespacePingLayer.cpp
index 00b931b..5ea5423 100644
--- a/Swiften/StreamStack/WhitespacePingLayer.cpp
+++ b/Swiften/StreamStack/WhitespacePingLayer.cpp
@@ -1,47 +1,56 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/StreamStack/WhitespacePingLayer.h>
#include <boost/bind.hpp>
-#include <Swiften/Network/TimerFactory.h>
+#include <Swiften/Base/Log.h>
#include <Swiften/Network/Timer.h>
+#include <Swiften/Network/TimerFactory.h>
namespace Swift {
static const int TIMEOUT_MILLISECONDS = 60000;
WhitespacePingLayer::WhitespacePingLayer(TimerFactory* timerFactory) : isActive(false) {
timer = timerFactory->createTimer(TIMEOUT_MILLISECONDS);
timer->onTick.connect(boost::bind(&WhitespacePingLayer::handleTimerTick, this));
}
+WhitespacePingLayer::~WhitespacePingLayer() {
+ SWIFT_LOG_ASSERT(!isActive, debug) << "WhitespacePingLayer still active at destruction." << std::endl;
+ if (isActive) {
+ timer->stop();
+ }
+ timer->onTick.disconnect(boost::bind(&WhitespacePingLayer::handleTimerTick, this));
+}
+
void WhitespacePingLayer::writeData(const SafeByteArray& data) {
writeDataToChildLayer(data);
}
void WhitespacePingLayer::handleDataRead(const SafeByteArray& data) {
writeDataToParentLayer(data);
}
void WhitespacePingLayer::handleTimerTick() {
timer->stop();
writeDataToChildLayer(createSafeByteArray(" "));
timer->start();
}
void WhitespacePingLayer::setActive() {
isActive = true;
timer->start();
}
void WhitespacePingLayer::setInactive() {
timer->stop();
isActive = false;
}
}
diff --git a/Swiften/StreamStack/WhitespacePingLayer.h b/Swiften/StreamStack/WhitespacePingLayer.h
index 17b0654..7ed56ca 100644
--- a/Swiften/StreamStack/WhitespacePingLayer.h
+++ b/Swiften/StreamStack/WhitespacePingLayer.h
@@ -1,39 +1,40 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <Swiften/Base/API.h>
#include <Swiften/StreamStack/StreamLayer.h>
namespace Swift {
class Timer;
class TimerFactory;
class SWIFTEN_API WhitespacePingLayer : public StreamLayer, boost::noncopyable {
public:
WhitespacePingLayer(TimerFactory* timerFactory);
+ virtual ~WhitespacePingLayer();
void setActive();
void setInactive();
void writeData(const SafeByteArray& data);
void handleDataRead(const SafeByteArray& data);
bool getIsActive() const {
return isActive;
}
private:
void handleTimerTick();
private:
bool isActive;
boost::shared_ptr<Timer> timer;
};
}