From 7a76337e897a8c0343f6de9160da414249cfb640 Mon Sep 17 00:00:00 2001 From: emv Date: Thu, 7 Aug 2014 10:09:12 +0400 Subject: [PATCH] 0025128: Memory leak in BOPDS_DS::Paves() class BOPDS_DS method void BOPDS_DS::Paves(const Standard_Integer theEdge, BOPDS_ListOfPave& theLP) class BOPDS_PaveBlock method void BOPDS_PaveBlock::Update(BOPDS_ListOfPaveBlock& theLPB, const Standard_Boolean theFlag) Using NCollection_Array1 class to ensure proper allocation and deallocation of memory. --- src/BOPDS/BOPDS.cdl | 3 +- src/BOPDS/BOPDS_DS.cxx | 75 +++++++++++------------------- src/BOPDS/BOPDS_MapOfPave.hxx | 2 +- src/BOPDS/BOPDS_PaveBlock.cxx | 78 +++++++++----------------------- src/BOPDS/BOPDS_VectorOfPave.hxx | 23 ++++++++++ src/BOPDS/FILES | 2 +- 6 files changed, 74 insertions(+), 109 deletions(-) create mode 100644 src/BOPDS/BOPDS_VectorOfPave.hxx diff --git a/src/BOPDS/BOPDS.cdl b/src/BOPDS/BOPDS.cdl index 7d1d0a794a..2094b7418e 100644 --- a/src/BOPDS/BOPDS.cdl +++ b/src/BOPDS/BOPDS.cdl @@ -111,8 +111,9 @@ is imported VectorOfInterfFZ from BOPDS; imported VectorOfInterfZZ from BOPDS; -- - imported VectorOfPoint from BOPDS; + imported VectorOfPoint from BOPDS; imported VectorOfCurve from BOPDS; + imported VectorOfPave from BOPDS; -- end BOPDS; diff --git a/src/BOPDS/BOPDS_DS.cxx b/src/BOPDS/BOPDS_DS.cxx index b9495103ed..fc8ee91556 100644 --- a/src/BOPDS/BOPDS_DS.cxx +++ b/src/BOPDS/BOPDS_DS.cxx @@ -14,6 +14,8 @@ #include // +#include +// #include #include @@ -40,6 +42,7 @@ #include #include #include +#include #include #include @@ -48,6 +51,8 @@ #include #include +#include + // static inline void ResetShape(const TopoDS_Shape& aS); @@ -62,8 +67,6 @@ static static Standard_Real ComputeParameter(const TopoDS_Vertex& aV, const TopoDS_Edge& aE); -static - void SortShell(const int n, BOPDS_Pave *a); //======================================================================= //function : @@ -1752,36 +1755,41 @@ void BOPDS_DS::Paves(const Standard_Integer theEdge, BOPDS_ListOfPave& theLP) { Standard_Integer aNb, i; - BOPDS_Pave *pPaves; BOPDS_ListIteratorOfListOfPaveBlock aIt; BOPDS_MapOfPave aMP; // const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(theEdge); - aNb = aLPB.Extent(); - aNb = (aNb==0) ? 0 : (aNb+1); - // - pPaves=(BOPDS_Pave *)myAllocator->Allocate(aNb*sizeof(BOPDS_Pave)); - for (i=0; iPave1())){ - pPaves[i] = aPB->Pave1(); + const BOPDS_Pave& aPave1 = aPB->Pave1(); + const BOPDS_Pave& aPave2 = aPB->Pave2(); + // + if (aMP.Add(aPave1)){ + pPaves(i) = aPave1; ++i; } - if (aMP.Add(aPB->Pave2())){ - pPaves[i] = aPB->Pave2(); + // + if (aMP.Add(aPave2)){ + pPaves(i) = aPave2; ++i; } } // - SortShell(aNb, pPaves); + Standard_ASSERT_VOID(aNb == aMP.Extent(), "Abnormal number of paves"); // - for (i = 0; i < aNb; ++i) { - theLP.Append(pPaves[i]); + std::sort(pPaves.begin(), pPaves.end()); + // + for (i = 1; i <= aNb; ++i) { + theLP.Append(pPaves(i)); } } @@ -1905,37 +1913,6 @@ Standard_Real ComputeParameter(const TopoDS_Vertex& aV, return aTRet; } //======================================================================= -// function: SortShell -// purpose : -//======================================================================= -void SortShell(const int n, BOPDS_Pave *a) -{ - int nd, i, j, l, d=1; - BOPDS_Pave x; - // - while(d<=n) { - d*=2; - } - // - while (d) { - d=(d-1)/2; - // - nd=n-d; - for (i=0; i -1) goto m30; - }//if (a[l] < a[j]){ - }//for (i=0; i typedef NCollection_Map BOPDS_MapOfPave; -typedef BOPDS_MapOfPave::Iterator BOPDS_MapIteratorMapOfPave; +typedef BOPDS_MapOfPave::Iterator BOPDS_MapIteratorOfMapOfPave; #endif diff --git a/src/BOPDS/BOPDS_PaveBlock.cxx b/src/BOPDS/BOPDS_PaveBlock.cxx index 84f5ba6487..14ff6a27c4 100755 --- a/src/BOPDS/BOPDS_PaveBlock.cxx +++ b/src/BOPDS/BOPDS_PaveBlock.cxx @@ -14,17 +14,17 @@ #include #include +#include + #include #include +#include #ifdef WNT #pragma warning ( disable : 4291 ) #endif -static - void SortShell(const int n, BOPDS_Pave *a); - //======================================================================= //function : //purpose : @@ -262,7 +262,6 @@ static const Standard_Boolean theFlag) { Standard_Integer i, aNb; - BOPDS_Pave *pPaves; BOPDS_Pave aPave1, aPave2; Handle(BOPDS_PaveBlock) aPB; BOPDS_ListIteratorOfListOfPave aIt; @@ -272,86 +271,51 @@ static aNb=aNb+2; } // - pPaves=(BOPDS_Pave *)myAllocator->Allocate(aNb*sizeof(BOPDS_Pave)); - for (i=0; iSetOriginalEdge(myOriginalEdge); aPB->SetPave1(aPave1); aPB->SetPave2(aPave2); // theLPB.Append(aPB); // - aPave1=aPave2; + aPave1 = aPave2; } - // - for (i=0; iFree(pPaves); } - -//======================================================================= -// function: SortShell -// purpose : -//======================================================================= -void SortShell(const int n, BOPDS_Pave *a) -{ - int nd, i, j, l, d=1; - BOPDS_Pave x; - // - while(d<=n) { - d*=2; - } - // - while (d) { - d=(d-1)/2; - // - nd=n-d; - for (i=0; i -1) goto m30; - }//if (a[l] < a[j]){ - }//for (i=0; i +#include + +typedef NCollection_Array1 BOPDS_VectorOfPave; + +#endif diff --git a/src/BOPDS/FILES b/src/BOPDS/FILES index 0af176ffb1..9c4dc2f1ce 100644 --- a/src/BOPDS/FILES +++ b/src/BOPDS/FILES @@ -36,4 +36,4 @@ BOPDS_IndexedMapOfPaveBlock.hxx BOPDS_IndexedDataMapOfPaveBlockListOfInteger.hxx BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks.hxx BOPDS_DataMapOfPaveBlockCommonBlock.hxx - +BOPDS_VectorOfPave.hxx \ No newline at end of file