diff options
author | Yuri Gorshenin <ygorshenin@chromium.org> | 2015-03-13 13:47:42 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:39:06 +0300 |
commit | e300e2b4313b9eb2fa9d5ef3cdad1216ffec03fa (patch) | |
tree | fe4ba1deabc22930e7e92f05dffb55bf1b04d4e1 /map/user_mark_container.cpp | |
parent | e8919af8ae240b37a652d93a1b82b969326dd8aa (diff) |
[bookmarks] Fixed memory leaks in Bookmarks test.
Diffstat (limited to 'map/user_mark_container.cpp')
-rw-r--r-- | map/user_mark_container.cpp | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/map/user_mark_container.cpp b/map/user_mark_container.cpp index 9a8c665c22..0351a943e5 100644 --- a/map/user_mark_container.cpp +++ b/map/user_mark_container.cpp @@ -16,7 +16,6 @@ #include "../base/macros.hpp" #include "../base/stl_add.hpp" -#include "../std/unique_ptr.hpp" #include "../std/algorithm.hpp" //////////////////////////////////////////////////////////////////////// @@ -138,7 +137,7 @@ void UserMarkContainer::ForEachInRect(m2::RectD const & rect, ToDo toDo) const { for (size_t i = 0; i < m_userMarks.size(); ++i) if (rect.IsPointInside(m_userMarks[i]->GetOrg())) - toDo(m_userMarks[i]); + toDo(m_userMarks[i].get()); } UserMark const * UserMarkContainer::FindMarkInRect(m2::AnyRectD const & rect, double & d) const @@ -166,9 +165,6 @@ void UserMarkContainer::Draw(PaintOverlayEvent const & e, UserMarkDLCache * cach void UserMarkContainer::Clear(size_t skipCount/* = 0*/) { - for (size_t i = skipCount; i < m_userMarks.size(); ++i) - delete m_userMarks[i]; - if (skipCount < m_userMarks.size()) m_userMarks.erase(m_userMarks.begin() + skipCount, m_userMarks.end()); } @@ -202,9 +198,8 @@ MyPositionMarkPoint * UserMarkContainer::UserMarkForMyPostion() UserMark * UserMarkContainer::CreateUserMark(m2::PointD const & ptOrg) { - unique_ptr<UserMark> mark(AllocateUserMark(ptOrg)); - m_userMarks.push_front(mark.get()); - return mark.release(); + m_userMarks.push_front(unique_ptr<UserMark>(AllocateUserMark(ptOrg))); + return m_userMarks.front().get(); } size_t UserMarkContainer::GetUserMarkCount() const @@ -215,40 +210,38 @@ size_t UserMarkContainer::GetUserMarkCount() const UserMark const * UserMarkContainer::GetUserMark(size_t index) const { ASSERT_LESS(index, m_userMarks.size(), ()); - return m_userMarks[index]; + return m_userMarks[index].get(); } UserMark * UserMarkContainer::GetUserMark(size_t index) { ASSERT_LESS(index, m_userMarks.size(), ()); - return m_userMarks[index]; + return m_userMarks[index].get(); } void UserMarkContainer::DeleteUserMark(size_t index) { ASSERT_LESS(index, m_userMarks.size(), ()); if (index < m_userMarks.size()) - { - delete m_userMarks[index]; m_userMarks.erase(m_userMarks.begin() + index); - } else - { LOG(LWARNING, ("Trying to delete non-existing item at index", index)); - } } void UserMarkContainer::DeleteUserMark(UserMark const * mark) { - UserMarksListT::iterator it = find(m_userMarks.begin(), m_userMarks.end(), mark); - if (it != m_userMarks.end()) - DeleteUserMark(distance(m_userMarks.begin(), it)); + size_t index = FindUserMark(mark); + if (index != m_userMarks.size()) + DeleteUserMark(index); } size_t UserMarkContainer::FindUserMark(UserMark const * mark) { - return distance(m_userMarks.begin(), - find(m_userMarks.begin(), m_userMarks.end(), mark)); + auto it = find_if(m_userMarks.begin(), m_userMarks.end(), [&mark](unique_ptr<UserMark> const & p) + { + return p.get() == mark; + }); + return distance(m_userMarks.begin(), it); } SearchUserMarkContainer::SearchUserMarkContainer(double layerDepth, Framework & framework) |