diff --git a/src/MAT/MAT_ListOfBisector.hxx b/src/MAT/MAT_ListOfBisector.hxx index ce62b2e8d6..f4560b0c77 100644 --- a/src/MAT/MAT_ListOfBisector.hxx +++ b/src/MAT/MAT_ListOfBisector.hxx @@ -36,9 +36,10 @@ class MAT_ListOfBisector : public Standard_Transient public: - Standard_EXPORT MAT_ListOfBisector(); + Standard_EXPORT ~MAT_ListOfBisector(); + Standard_EXPORT void First(); Standard_EXPORT void Last(); diff --git a/src/MAT/MAT_ListOfEdge.hxx b/src/MAT/MAT_ListOfEdge.hxx index 4c842fd3f1..f43a08487f 100644 --- a/src/MAT/MAT_ListOfEdge.hxx +++ b/src/MAT/MAT_ListOfEdge.hxx @@ -36,8 +36,9 @@ class MAT_ListOfEdge : public Standard_Transient public: - Standard_EXPORT MAT_ListOfEdge(); + + Standard_EXPORT ~MAT_ListOfEdge(); Standard_EXPORT void First(); diff --git a/src/MAT/MAT_TList.gxx b/src/MAT/MAT_TList.gxx index 25540b3c6e..15d1f03d3f 100644 --- a/src/MAT/MAT_TList.gxx +++ b/src/MAT/MAT_TList.gxx @@ -197,22 +197,25 @@ void MAT_TList::Unlink() Standard_Boolean nextisnull = thecurrentnode->Next().IsNull(); if(thecurrentindex) + { + if(!nextisnull) { - if(!nextisnull && !previousisnull) - { - thecurrentnode->Next()->Previous(thecurrentnode->Previous()); - thecurrentnode->Previous()->Next(thecurrentnode->Next()); - } - - if(thecurrentindex == 1) - { - thefirstnode = thecurrentnode->Next(); - } - else if(thecurrentindex == thenumberofitems) - { - thelastnode = thecurrentnode->Previous(); - } + thecurrentnode->Next()->Previous(thecurrentnode->Previous()); } + if (!previousisnull) + { + thecurrentnode->Previous()->Next(thecurrentnode->Next()); + } + + if(thecurrentindex == 1) + { + thefirstnode = thecurrentnode->Next(); + } + else if(thecurrentindex == thenumberofitems) + { + thelastnode = thecurrentnode->Previous(); + } + } thenumberofitems--; thecurrentindex--; } @@ -382,3 +385,25 @@ void MAT_TList::Dump(const Standard_Integer ashift, { for(First(); More(); Next()) Current()->Dump(ashift,alevel); } + +//======================================================================= +//function : ~MAT_TList +//purpose : +//======================================================================= + +MAT_TList::~MAT_TList() +{ + Handle(MAT_TListNode) aNode = thefirstnode; + while (!aNode.IsNull()) + { + Handle(MAT_TListNode) aNext = aNode->Next(); + aNode->Next (NULL); + aNode->Previous (NULL); + aNode = aNext; + } + thecurrentnode.Nullify(); + thefirstnode.Nullify(); + thelastnode.Nullify(); + thecurrentindex = 0; + thenumberofitems = 0; +} diff --git a/src/MAT2d/MAT2d_Mat2d.cxx b/src/MAT2d/MAT2d_Mat2d.cxx index 96d190edfc..9f24c154ee 100644 --- a/src/MAT2d/MAT2d_Mat2d.cxx +++ b/src/MAT2d/MAT2d_Mat2d.cxx @@ -183,6 +183,7 @@ void MAT2d_Mat2d::CreateMatOpen(MAT2d_Tool2d& atool) // du contour. // -------------------------------------------------------------------- theedgelist = new MAT_ListOfEdge(); + RemovedEdgesList = new MAT_ListOfEdge(); for(i=0; iNext(); } - + + RemovedEdgesList->BackAdd(theedgelist->Current()); theedgelist->Unlink(); //----------------------------------------------------------- @@ -623,6 +625,7 @@ void MAT2d_Mat2d::CreateMatOpen(MAT2d_Tool2d& atool) ->FirstBisector()); for(j=0; jBackAdd(theedgelist->Current()); theedgelist->Unlink(); theedgelist->Next(); shift++; @@ -851,6 +854,7 @@ void MAT2d_Mat2d::CreateMat(MAT2d_Tool2d& atool) // du contour. // -------------------------------------------------------------------- theedgelist = new MAT_ListOfEdge(); + RemovedEdgesList = new MAT_ListOfEdge(); for(i=0; iNext(); } + RemovedEdgesList->BackAdd(theedgelist->Current()); theedgelist->Unlink(); //----------------------------------------------------------- @@ -1329,6 +1334,7 @@ void MAT2d_Mat2d::CreateMat(MAT2d_Tool2d& atool) ->FirstBisector()); for(j=0; jBackAdd(theedgelist->Current()); theedgelist->Unlink(); theedgelist->Next(); shift++; @@ -1710,3 +1716,41 @@ Standard_Boolean MAT2d_Mat2d::IsDone() const return isDone; } +//======================================================================= +//function : ~MAT2d_Mat2d +//purpose : +//======================================================================= + +MAT2d_Mat2d::~MAT2d_Mat2d() +{ + MAT_DataMapIteratorOfDataMapOfIntegerBisector itmap(bisectormap); + for (; itmap.More(); itmap.Next()) + { + Handle(MAT_Bisector) aBisector = itmap.Value(); + aBisector->FirstEdge(NULL); + aBisector->SecondEdge(NULL); + } + + if (!theedgelist.IsNull()) + { + theedgelist->First(); + for (Standard_Integer i = 1; i <= theedgelist->Number(); i++) + { + Handle(MAT_Edge) anEdge = theedgelist->Current(); + anEdge->FirstBisector(NULL); + anEdge->SecondBisector(NULL); + theedgelist->Next(); + } + } + if (!RemovedEdgesList.IsNull()) + { + RemovedEdgesList->First(); + for (Standard_Integer i = 1; i <= RemovedEdgesList->Number(); i++) + { + Handle(MAT_Edge) anEdge = RemovedEdgesList->Current(); + anEdge->FirstBisector(NULL); + anEdge->SecondBisector(NULL); + RemovedEdgesList->Next(); + } + } +} diff --git a/src/MAT2d/MAT2d_Mat2d.hxx b/src/MAT2d/MAT2d_Mat2d.hxx index 50515f9b1b..568399c2de 100644 --- a/src/MAT2d/MAT2d_Mat2d.hxx +++ b/src/MAT2d/MAT2d_Mat2d.hxx @@ -44,6 +44,8 @@ public: //! Empty construtor. Standard_EXPORT MAT2d_Mat2d(const Standard_Boolean IsOpenResult = Standard_False); + Standard_EXPORT ~MAT2d_Mat2d(); + //! Algoritm of computation of the bisecting locus. Standard_EXPORT void CreateMat (MAT2d_Tool2d& aTool); @@ -96,6 +98,7 @@ private: Standard_Integer thenumberofedges; Standard_Boolean semiInfinite; Handle(MAT_ListOfEdge) theedgelist; + Handle(MAT_ListOfEdge) RemovedEdgesList; TColStd_DataMapOfIntegerInteger typeofbisectortoremove; MAT_DataMapOfIntegerBisector bisectoronetoremove; MAT_DataMapOfIntegerBisector bisectortwotoremove; diff --git a/tests/bugs/modalg_7/bug31120 b/tests/bugs/modalg_7/bug31120 new file mode 100644 index 0000000000..f351bc8f8c --- /dev/null +++ b/tests/bugs/modalg_7/bug31120 @@ -0,0 +1,22 @@ +puts "=================================================" +puts "OCC31120: Memory leak in BRepOffsetAPI_MakeOffset" +puts "=================================================" +puts "" + +restore [locate_data_file bug31120_wire.brep] w + +mkoffset r w 1 0.5 +set log [meminfo h] +regexp {([0-9+-.eE]*)} $log full memval1 + +for {set i 0} {$i < 20} {incr i} { + mkoffset r w 1 0.5 + set log [meminfo h] + regexp {([0-9+-.eE]*)} $log full memval + + set ratio (${memval}-{$memval1})/${memval1} + + if { ${ratio} > 0.05} { + puts "Error: memory leak" + } +}