[Libreoffice-commits] core.git: Branch 'libreoffice-4-3' - sc/source
Markus Mohrhard
markus.mohrhard at googlemail.com
Tue Aug 12 01:13:32 PDT 2014
sc/source/core/tool/chartlis.cxx | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
New commits:
commit 99784de15a9921c47799201b555632eefe9d37a3
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Thu Jul 31 22:09:55 2014 +0200
fix memory leak around chart listeners
Found by Lsan.
The following pattern leaks memory:
boost::ptr_container x;
x.release().release();
Change-Id: Iaf52e4f2d6a96266fc6afd65ef8027d80c97a08b
(cherry picked from commit 42cd7a8a26201fa1db98d6498198db23abef87fc)
Reviewed-on: https://gerrit.libreoffice.org/10741
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/sc/source/core/tool/chartlis.cxx b/sc/source/core/tool/chartlis.cxx
index 6e15d77..4a96cf6 100644
--- a/sc/source/core/tool/chartlis.cxx
+++ b/sc/source/core/tool/chartlis.cxx
@@ -544,39 +544,32 @@ public:
void ScChartListenerCollection::FreeUnused()
{
- std::vector<ScChartListener*> aUsed, aUnused;
+ ListenersType aUsed, aUnused;
// First, filter each listener into 'used' and 'unused' categories.
{
- ListenersType::iterator it = maListeners.begin(), itEnd = maListeners.end();
- for (; it != itEnd; ++it)
+ while(!maListeners.empty())
{
- ScChartListener* p = it->second;
+ ScChartListener* p = maListeners.begin()->second;
if (p->IsUno())
{
// We don't delete UNO charts; they are to be deleted separately via FreeUno().
- aUsed.push_back(p);
+ aUsed.transfer(maListeners.begin(), maListeners);
continue;
}
if (p->IsUsed())
{
p->SetUsed(false);
- aUsed.push_back(p);
+ aUsed.transfer(maListeners.begin(), maListeners);
}
else
- aUnused.push_back(p);
+ aUnused.transfer(maListeners.begin(), maListeners);
+
}
}
- // Release all pointers currently managed by the ptr_map container.
- maListeners.release().release();
-
- // Re-insert the listeners we need to keep.
- std::for_each(aUsed.begin(), aUsed.end(), InsertChartListener(maListeners));
-
- // Now, delete the ones no longer needed.
- std::for_each(aUnused.begin(), aUnused.end(), boost::checked_deleter<ScChartListener>());
+ std::swap(aUsed, maListeners);
}
void ScChartListenerCollection::FreeUno( const uno::Reference< chart::XChartDataChangeEventListener >& rListener,
More information about the Libreoffice-commits
mailing list