0031120: Memory leak in BRepOffsetAPI_MakeOffset
authormsv <msv@opencascade.com>
Fri, 1 Nov 2019 12:05:43 +0000 (15:05 +0300)
committerjgv <jgv@opencascade.com>
Tue, 17 Dec 2019 12:51:06 +0000 (15:51 +0300)
Add destructor of MAT2d_Mat2d - full removal of edges and bisectors.

src/MAT/MAT_ListOfBisector.hxx
src/MAT/MAT_ListOfEdge.hxx
src/MAT/MAT_TList.gxx
src/MAT2d/MAT2d_Mat2d.cxx
src/MAT2d/MAT2d_Mat2d.hxx
tests/bugs/modalg_7/bug31120 [new file with mode: 0644]

index ce62b2e..f4560b0 100644 (file)
@@ -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();
index 4c842fd..f43a084 100644 (file)
@@ -36,8 +36,9 @@ class MAT_ListOfEdge : public Standard_Transient
 
 public:
 
-  
   Standard_EXPORT MAT_ListOfEdge();
+
+  Standard_EXPORT ~MAT_ListOfEdge();
   
   Standard_EXPORT void First();
   
index 25540b3..15d1f03 100644 (file)
@@ -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());
-       }
+      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();
-       }
+    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;
+}
index 96d190e..9f24c15 100644 (file)
@@ -183,6 +183,7 @@ void MAT2d_Mat2d::CreateMatOpen(MAT2d_Tool2d& atool)
 // du contour.
 // --------------------------------------------------------------------
   theedgelist = new MAT_ListOfEdge();
+  RemovedEdgesList = new MAT_ListOfEdge();
 
   for(i=0; i<noofedges; i++) {
     edge = new MAT_Edge();
@@ -401,7 +402,8 @@ void MAT2d_Mat2d::CreateMatOpen(MAT2d_Tool2d& atool)
            previousedge = currentedge;
            currentbisectorlist->Next();
          }
-         
+
+          RemovedEdgesList->BackAdd(theedgelist->Current());
          theedgelist->Unlink();
 
          //-----------------------------------------------------------
@@ -623,6 +625,7 @@ void MAT2d_Mat2d::CreateMatOpen(MAT2d_Tool2d& atool)
                                                 ->FirstBisector());
 
       for(j=0; j<noofarea(i); j++) {
+        RemovedEdgesList->BackAdd(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; i<noofedges; i++) {
     edge = new MAT_Edge();
@@ -1103,6 +1107,7 @@ void MAT2d_Mat2d::CreateMat(MAT2d_Tool2d& atool)
             currentbisectorlist->Next();
           }
 
+          RemovedEdgesList->BackAdd(theedgelist->Current());
           theedgelist->Unlink();
 
           //-----------------------------------------------------------
@@ -1329,6 +1334,7 @@ void MAT2d_Mat2d::CreateMat(MAT2d_Tool2d& atool)
         ->FirstBisector());
 
       for(j=0; j<noofarea(i); j++) {
+        RemovedEdgesList->BackAdd(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();
+    }
+  }
+}
index 50515f9..568399c 100644 (file)
@@ -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 (file)
index 0000000..f351bc8
--- /dev/null
@@ -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"
+  }
+}