From fe1dd7872dcb999919a348c5edb283b335863d21 Mon Sep 17 00:00:00 2001 From: Paul Wisbey Date: Wed, 3 Sep 2014 13:59:15 +0100 Subject: [PATCH] Fixed memory leak when connecting static functions [problem] Callback object is leaked when not using ConnectionTracker e.g. when connecting static functions. [cause] Ownership of Callback was not taken (no SlotConnection created). [solution] Moved ownership to SignalConnection which is always created. Change-Id: Ie828f58a72d6badab5a72f66af0e765c6fbe7434 --- .../signals/signal-slot-connections.cpp | 4 ++-- dali/public-api/signals/signal-slot-connections.h | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/dali/public-api/signals/signal-slot-connections.cpp b/dali/public-api/signals/signal-slot-connections.cpp index c74d3c9bf..ab22e094b 100644 --- a/dali/public-api/signals/signal-slot-connections.cpp +++ b/dali/public-api/signals/signal-slot-connections.cpp @@ -32,8 +32,6 @@ SlotConnection::SlotConnection( SlotObserver* slotObserver, CallbackBase* callba SlotConnection::~SlotConnection() { - // slot connections have ownership of the callback. - delete mCallback; } CallbackBase* SlotConnection::GetCallback() @@ -60,6 +58,8 @@ SignalConnection::SignalConnection( SignalObserver* signalObserver, CallbackBase SignalConnection::~SignalConnection() { + // signal connections have ownership of the callback. + delete mCallback; } void SignalConnection::Disconnect( SlotObserver* slotObserver ) diff --git a/dali/public-api/signals/signal-slot-connections.h b/dali/public-api/signals/signal-slot-connections.h index f81f58427..5c8c20ab9 100644 --- a/dali/public-api/signals/signal-slot-connections.h +++ b/dali/public-api/signals/signal-slot-connections.h @@ -36,8 +36,7 @@ class CallbackBase; * - Callback (slot) * - SlotObserver -interface provided by the signal * - * It takes ownership of the callback, and will delete it when - * the connection is destroyed. + * It holds a pointer to the callback, but does not own it. */ class SlotConnection { @@ -47,7 +46,7 @@ public: * @brief Constructor. * * @param[in] slotObserver The slot observer. - * @param[in] callback Ownership of this callback object is taken. + * @param[in] callback A callback object (not owned). */ SlotConnection(SlotObserver* slotObserver, CallbackBase* callback); @@ -78,7 +77,7 @@ private: private: SlotObserver* mSlotObserver; ///< a pointer to the slot observer (not owned) - CallbackBase* mCallback; ///< callback, has ownership + CallbackBase* mCallback; ///< The callback. This is not owned, the corresponding SignalConnection has ownership. }; /** @@ -91,8 +90,8 @@ private: * - Callback (slot) * - SignalObserver - interface provided by a slot owning object. * - * It holds a pointer to the callback, but does not own it. - * + * It takes ownership of the callback, and will delete it when + * the connection is destroyed. */ class SignalConnection { @@ -109,7 +108,7 @@ public: * @brief Constructor. * * @param[in] signalObserver The signal observer. - * @param[in] callback The callback which should be a member function of the signalObserver. + * @param[in] callback Ownership of this callback object is taken. */ SignalConnection( SignalObserver* signalObserver, CallbackBase* callback ); @@ -140,7 +139,7 @@ private: private: SignalObserver* mSignalObserver; ///< a pointer to the signal observer (not owned) - CallbackBase* mCallback; ///< The callback. This is not owned, the corresponding SlotConnection has ownership. + CallbackBase* mCallback; ///< The callback, has ownership. }; } // namespace Dali -- 2.34.1