From aca23dea594cdbb8cf9c443fc7f3ac118ce5cebb Mon Sep 17 00:00:00 2001
From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be>
Date: Fri, 26 Mar 2010 11:15:57 +0000
Subject: [PATCH] functions : remove memory leak

---
 Solver/function.cpp | 6 +++---
 Solver/function.h   | 8 ++------
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/Solver/function.cpp b/Solver/function.cpp
index 4508cdfe41..7771988a27 100644
--- a/Solver/function.cpp
+++ b/Solver/function.cpp
@@ -92,8 +92,8 @@ dataCacheDouble &dataCacheMap::substitute(const function *f)
 
 dataCacheMap::~dataCacheMap()
 {
-  for (std::set<dataCacheDouble*>::iterator it = _toDelete.begin();
-      it!=_toDelete.end(); it++) {
+  for (std::set<dataCacheDouble*>::iterator it = _allDataCaches.begin();
+      it!=_allDataCaches.end(); it++) {
     delete *it;
   }
 }
@@ -309,7 +309,7 @@ class functionLua : public function {
 
 void dataCacheMap::setNbEvaluationPoints(int nbEvaluationPoints) {
   _nbEvaluationPoints = nbEvaluationPoints;
-  for(std::set<dataCacheDouble*>::iterator it = _toResize.begin(); it!= _toResize.end(); it++){
+  for(std::set<dataCacheDouble*>::iterator it = _allDataCaches.begin(); it!= _allDataCaches.end(); it++){
     (*it)->resize();
     (*it)->_valid = false;
   }
diff --git a/Solver/function.h b/Solver/function.h
index 38a62b9811..53c528d33a 100644
--- a/Solver/function.h
+++ b/Solver/function.h
@@ -147,18 +147,14 @@ class dataCacheMap {
   std::list<dataCacheMap*> _children;
   int _nbEvaluationPoints;
   std::map<const function*, dataCacheDouble*> _cacheDoubleMap;
-  std::set<dataCacheDouble*> _toDelete;
-  std::set<dataCacheDouble*> _toResize;
+  std::set<dataCacheDouble*> _allDataCaches;
   std::set<dataCacheDouble*> _toInvalidateOnElement;
 
   MElement *_element;
 
  protected:
-  void addDataCache(dataCacheDouble *data){
-    _toDelete.insert(data);
-  }
   void addDataCacheDouble(dataCacheDouble *data, bool invalidatedOnElement){
-    _toResize.insert(data);
+    _allDataCaches.insert(data);
     if(invalidatedOnElement)
       _toInvalidateOnElement.insert(data);
   }
-- 
GitLab