From ab1fff7fb56de38d9df3c6fba9c4efec9a3042bd Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Tue, 20 Jan 2015 22:32:15 +0100 Subject: Fix ASAN reported use-after-free error The class connects to SettingsProvider::onSettingChanged in its c-tor but never disconnects from the signal. When an instance is deleted and the signal is called afterwards it will call the method which will try to access class members which have already been deleted. Test-Information: Tested on OS X 10.9.5. ASAN reported it sometimes on exit. Have not been able to reproduc it anymore with this fix. Change-Id: I7f1d815dca87f84a4ae93a5455307e261a1ee329 diff --git a/Swift/Controllers/HighlightManager.cpp b/Swift/Controllers/HighlightManager.cpp index e2498dc..ed49e72 100644 --- a/Swift/Controllers/HighlightManager.cpp +++ b/Swift/Controllers/HighlightManager.cpp @@ -51,7 +51,7 @@ HighlightManager::HighlightManager(SettingsProvider* settings) { rules_ = boost::make_shared(); loadSettings(); - settings_->onSettingChanged.connect(boost::bind(&HighlightManager::handleSettingChanged, this, _1)); + handleSettingChangedConnection_ = settings_->onSettingChanged.connect(boost::bind(&HighlightManager::handleSettingChanged, this, _1)); } void HighlightManager::handleSettingChanged(const std::string& settingPath) diff --git a/Swift/Controllers/HighlightManager.h b/Swift/Controllers/HighlightManager.h index d37643d..c55990b 100644 --- a/Swift/Controllers/HighlightManager.h +++ b/Swift/Controllers/HighlightManager.h @@ -67,10 +67,12 @@ namespace Swift { std::string rulesToString() const; static std::vector getDefaultRules(); + private: SettingsProvider* settings_; bool storingSettings_; boost::shared_ptr rules_; + boost::bsignals::scoped_connection handleSettingChangedConnection_; }; typedef boost::shared_ptr HighlightRulesListPtr; -- cgit v0.10.2-6-g49f6