From: Eugene Kurzberg Date: Tue, 10 May 2016 13:29:34 +0000 (+0300) Subject: Fixed possible memory leak in ListView sections. X-Git-Tag: submit/tizen/20160524.113145~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F51%2F67951%2F3;p=profile%2Fmobile%2Fapps%2Fnative%2Fphone-contacts.git Fixed possible memory leak in ListView sections. Change-Id: Ie53318c032ddfaf6eea7358718066cb58f4d872e Signed-off-by: Eugene Kurzberg --- diff --git a/lib-apps-common/inc/Ui/Control.h b/lib-apps-common/inc/Ui/Control.h index 9675dc1..401c1ab 100644 --- a/lib-apps-common/inc/Ui/Control.h +++ b/lib-apps-common/inc/Ui/Control.h @@ -101,12 +101,17 @@ namespace Ui */ virtual void onCreated() { } + /** + * @brief Called before Control is destroyed. + */ + virtual void onDestroy() { } + private: void setEvasObject(Evas_Object *object); Evas_Object *resetEvasObject(); void destroyEvasObject(); - void onDestroy(Evas *e, Evas_Object *obj, void *event_info); + void onDestroyed(Evas *e, Evas_Object *obj, void *event_info); int m_Type; Evas_Object *m_Object; diff --git a/lib-apps-common/src/Ui/Control.cpp b/lib-apps-common/src/Ui/Control.cpp index c75add4..e54434b 100644 --- a/lib-apps-common/src/Ui/Control.cpp +++ b/lib-apps-common/src/Ui/Control.cpp @@ -82,15 +82,19 @@ void Control::setEvasObject(Evas_Object *object) evas_object_data_set(m_Object, CONTROL_DATA_KEY, this); } + evas_object_event_callback_add(m_Object, EVAS_CALLBACK_DEL, + (Evas_Object_Event_Cb) makeCallback(&Control::onDestroy), this); evas_object_event_callback_add(m_Object, EVAS_CALLBACK_FREE, - makeCallback(&Control::onDestroy), this); + makeCallback(&Control::onDestroyed), this); } Evas_Object *Control::resetEvasObject() { Evas_Object *object = m_Object; + evas_object_event_callback_del_full(m_Object, EVAS_CALLBACK_DEL, + (Evas_Object_Event_Cb) makeCallback(&Control::onDestroy), this); evas_object_event_callback_del_full(m_Object, EVAS_CALLBACK_FREE, - makeCallback(&Control::onDestroy), this); + makeCallback(&Control::onDestroyed), this); m_Object = nullptr; return object; } @@ -98,12 +102,13 @@ Evas_Object *Control::resetEvasObject() void Control::destroyEvasObject() { if (m_Object) { + onDestroy(); evas_object_del(resetEvasObject()); } } -void Control::onDestroy(Evas *e, Evas_Object *obj, void *event_info) +void Control::onDestroyed(Evas *e, Evas_Object *obj, void *event_info) { - resetEvasObject(); + m_Object = nullptr; delete this; } diff --git a/lib-contacts/inc/Contacts/List/ListView.h b/lib-contacts/inc/Contacts/List/ListView.h index 02da919..120a7f9 100644 --- a/lib-contacts/inc/Contacts/List/ListView.h +++ b/lib-contacts/inc/Contacts/List/ListView.h @@ -66,8 +66,10 @@ namespace Contacts }; virtual Evas_Object *onCreate(Evas_Object *parent) override; - virtual void onNavigation(bool isCurrent) override; virtual void onCreated() override; + virtual void onDestroy() override; + + virtual void onNavigation(bool isCurrent) override; virtual void onMenuPressed() override; void onDeleteSelected(); diff --git a/lib-contacts/src/Contacts/List/ListView.cpp b/lib-contacts/src/Contacts/List/ListView.cpp index 07ce959..070092a 100644 --- a/lib-contacts/src/Contacts/List/ListView.cpp +++ b/lib-contacts/src/Contacts/List/ListView.cpp @@ -88,13 +88,6 @@ Evas_Object *ListView::onCreate(Evas_Object *parent) return layout; } -void ListView::onNavigation(bool isCurrent) -{ - m_IsCurrentView = isCurrent; - updateAddButton(); - m_Provider.setUpdateMode(isCurrent); -} - void ListView::onCreated() { updateSectionsMode(); @@ -103,6 +96,22 @@ void ListView::onCreated() contacts_setting_add_name_sorting_order_changed_cb(onNameSortingOrderChanged, this); } +void ListView::onDestroy() +{ + for (auto &§ion : m_Sections) { + if (section && !section->isInserted()) { + delete section; + } + } +} + +void ListView::onNavigation(bool isCurrent) +{ + m_IsCurrentView = isCurrent; + updateAddButton(); + m_Provider.setUpdateMode(isCurrent); +} + void ListView::onMenuPressed() { if (getSelectMode() != SelectNone) {