From 702b8a31fbddaeb886ef242a0f8d3bc33d4786eb Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Tue, 31 May 2016 21:54:40 -0700 Subject: [PATCH] Avoid leaking the runloop and source if WeakRealmNotifier is move-assigned. --- src/impl/apple/weak_realm_notifier.cpp | 7 +++++++ src/impl/apple/weak_realm_notifier.hpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/impl/apple/weak_realm_notifier.cpp b/src/impl/apple/weak_realm_notifier.cpp index 0ce6300f..930c3fe7 100644 --- a/src/impl/apple/weak_realm_notifier.cpp +++ b/src/impl/apple/weak_realm_notifier.cpp @@ -69,6 +69,8 @@ WeakRealmNotifier::WeakRealmNotifier(WeakRealmNotifier&& rgt) WeakRealmNotifier& WeakRealmNotifier::operator=(WeakRealmNotifier&& rgt) { WeakRealmNotifierBase::operator=(std::move(rgt)); + + invalidate(); m_runloop = rgt.m_runloop; m_signal = rgt.m_signal; rgt.m_runloop = nullptr; @@ -78,6 +80,11 @@ WeakRealmNotifier& WeakRealmNotifier::operator=(WeakRealmNotifier&& rgt) } WeakRealmNotifier::~WeakRealmNotifier() +{ + invalidate(); +} + +void WeakRealmNotifier::invalidate() { if (m_signal) { CFRunLoopSourceInvalidate(m_signal); diff --git a/src/impl/apple/weak_realm_notifier.hpp b/src/impl/apple/weak_realm_notifier.hpp index 0f94ed7e..be940dcb 100644 --- a/src/impl/apple/weak_realm_notifier.hpp +++ b/src/impl/apple/weak_realm_notifier.hpp @@ -40,6 +40,8 @@ public: void notify(); private: + void invalidate(); + CFRunLoopRef m_runloop; CFRunLoopSourceRef m_signal; };