mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-21 10:13:43 +03:00
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.
This commit is contained in:
parent
5a89733fd4
commit
7a76337e89
@ -113,6 +113,7 @@ is
|
|||||||
--
|
--
|
||||||
imported VectorOfPoint from BOPDS;
|
imported VectorOfPoint from BOPDS;
|
||||||
imported VectorOfCurve from BOPDS;
|
imported VectorOfCurve from BOPDS;
|
||||||
|
imported VectorOfPave from BOPDS;
|
||||||
--
|
--
|
||||||
end BOPDS;
|
end BOPDS;
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include <BOPDS_DS.ixx>
|
#include <BOPDS_DS.ixx>
|
||||||
//
|
//
|
||||||
|
#include <Standard_Assert.hxx>
|
||||||
|
//
|
||||||
#include <NCollection_IncAllocator.hxx>
|
#include <NCollection_IncAllocator.hxx>
|
||||||
#include <NCollection_BaseAllocator.hxx>
|
#include <NCollection_BaseAllocator.hxx>
|
||||||
|
|
||||||
@ -40,6 +42,7 @@
|
|||||||
#include <BOPDS_PassKey.hxx>
|
#include <BOPDS_PassKey.hxx>
|
||||||
#include <BOPDS_MapOfPave.hxx>
|
#include <BOPDS_MapOfPave.hxx>
|
||||||
#include <BOPDS_MapOfPaveBlock.hxx>
|
#include <BOPDS_MapOfPaveBlock.hxx>
|
||||||
|
#include <BOPDS_VectorOfPave.hxx>
|
||||||
|
|
||||||
#include <Geom_Curve.hxx>
|
#include <Geom_Curve.hxx>
|
||||||
#include <BRep_Builder.hxx>
|
#include <BRep_Builder.hxx>
|
||||||
@ -48,6 +51,8 @@
|
|||||||
#include <BOPTools_AlgoTools.hxx>
|
#include <BOPTools_AlgoTools.hxx>
|
||||||
#include <GeomAPI_ProjectPointOnCurve.hxx>
|
#include <GeomAPI_ProjectPointOnCurve.hxx>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
//
|
//
|
||||||
static
|
static
|
||||||
inline void ResetShape(const TopoDS_Shape& aS);
|
inline void ResetShape(const TopoDS_Shape& aS);
|
||||||
@ -62,8 +67,6 @@ static
|
|||||||
static
|
static
|
||||||
Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
|
Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
|
||||||
const TopoDS_Edge& aE);
|
const TopoDS_Edge& aE);
|
||||||
static
|
|
||||||
void SortShell(const int n, BOPDS_Pave *a);
|
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function :
|
//function :
|
||||||
@ -1752,36 +1755,41 @@ void BOPDS_DS::Paves(const Standard_Integer theEdge,
|
|||||||
BOPDS_ListOfPave& theLP)
|
BOPDS_ListOfPave& theLP)
|
||||||
{
|
{
|
||||||
Standard_Integer aNb, i;
|
Standard_Integer aNb, i;
|
||||||
BOPDS_Pave *pPaves;
|
|
||||||
BOPDS_ListIteratorOfListOfPaveBlock aIt;
|
BOPDS_ListIteratorOfListOfPaveBlock aIt;
|
||||||
BOPDS_MapOfPave aMP;
|
BOPDS_MapOfPave aMP;
|
||||||
//
|
//
|
||||||
const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(theEdge);
|
const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(theEdge);
|
||||||
aNb = aLPB.Extent();
|
aNb = aLPB.Extent() + 1;
|
||||||
aNb = (aNb==0) ? 0 : (aNb+1);
|
if (aNb == 1) {
|
||||||
//
|
return;
|
||||||
pPaves=(BOPDS_Pave *)myAllocator->Allocate(aNb*sizeof(BOPDS_Pave));
|
|
||||||
for (i=0; i<aNb; ++i) {
|
|
||||||
new (pPaves+i) BOPDS_Pave();
|
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
i = 0;
|
BOPDS_VectorOfPave pPaves(1, aNb);
|
||||||
for (aIt.Initialize(aLPB); aIt.More(); aIt.Next()) {
|
//
|
||||||
|
i = 1;
|
||||||
|
aIt.Initialize(aLPB);
|
||||||
|
for (; aIt.More(); aIt.Next()) {
|
||||||
const Handle(BOPDS_PaveBlock)& aPB = aIt.Value();
|
const Handle(BOPDS_PaveBlock)& aPB = aIt.Value();
|
||||||
if (aMP.Add(aPB->Pave1())){
|
const BOPDS_Pave& aPave1 = aPB->Pave1();
|
||||||
pPaves[i] = aPB->Pave1();
|
const BOPDS_Pave& aPave2 = aPB->Pave2();
|
||||||
|
//
|
||||||
|
if (aMP.Add(aPave1)){
|
||||||
|
pPaves(i) = aPave1;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
if (aMP.Add(aPB->Pave2())){
|
//
|
||||||
pPaves[i] = aPB->Pave2();
|
if (aMP.Add(aPave2)){
|
||||||
|
pPaves(i) = aPave2;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
SortShell(aNb, pPaves);
|
Standard_ASSERT_VOID(aNb == aMP.Extent(), "Abnormal number of paves");
|
||||||
//
|
//
|
||||||
for (i = 0; i < aNb; ++i) {
|
std::sort(pPaves.begin(), pPaves.end());
|
||||||
theLP.Append(pPaves[i]);
|
//
|
||||||
|
for (i = 1; i <= aNb; ++i) {
|
||||||
|
theLP.Append(pPaves(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1905,37 +1913,6 @@ Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
|
|||||||
return aTRet;
|
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<nd; ++i) {
|
|
||||||
j=i;
|
|
||||||
m30:;
|
|
||||||
l=j+d;
|
|
||||||
if (a[l] < a[j]){
|
|
||||||
x=a[j];
|
|
||||||
a[j]=a[l];
|
|
||||||
a[l]=x;
|
|
||||||
j-=d;
|
|
||||||
if (j > -1) goto m30;
|
|
||||||
}//if (a[l] < a[j]){
|
|
||||||
}//for (i=0; i<nd; ++i)
|
|
||||||
}//while (1)
|
|
||||||
}
|
|
||||||
//=======================================================================
|
|
||||||
//function : BuildBndBoxSolid
|
//function : BuildBndBoxSolid
|
||||||
//purpose :
|
//purpose :
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
@ -20,6 +20,6 @@
|
|||||||
#include <BOPDS_Pave.hxx>
|
#include <BOPDS_Pave.hxx>
|
||||||
|
|
||||||
typedef NCollection_Map<BOPDS_Pave, BOPDS_PaveMapHasher> BOPDS_MapOfPave;
|
typedef NCollection_Map<BOPDS_Pave, BOPDS_PaveMapHasher> BOPDS_MapOfPave;
|
||||||
typedef BOPDS_MapOfPave::Iterator BOPDS_MapIteratorMapOfPave;
|
typedef BOPDS_MapOfPave::Iterator BOPDS_MapIteratorOfMapOfPave;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,17 +14,17 @@
|
|||||||
|
|
||||||
#include <BOPDS_PaveBlock.ixx>
|
#include <BOPDS_PaveBlock.ixx>
|
||||||
#include <BOPDS_ListOfPave.hxx>
|
#include <BOPDS_ListOfPave.hxx>
|
||||||
|
#include <BOPDS_VectorOfPave.hxx>
|
||||||
|
|
||||||
#include <Standard.hxx>
|
#include <Standard.hxx>
|
||||||
#include <NCollection_BaseAllocator.hxx>
|
#include <NCollection_BaseAllocator.hxx>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#ifdef WNT
|
#ifdef WNT
|
||||||
#pragma warning ( disable : 4291 )
|
#pragma warning ( disable : 4291 )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static
|
|
||||||
void SortShell(const int n, BOPDS_Pave *a);
|
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function :
|
//function :
|
||||||
//purpose :
|
//purpose :
|
||||||
@ -262,7 +262,6 @@ static
|
|||||||
const Standard_Boolean theFlag)
|
const Standard_Boolean theFlag)
|
||||||
{
|
{
|
||||||
Standard_Integer i, aNb;
|
Standard_Integer i, aNb;
|
||||||
BOPDS_Pave *pPaves;
|
|
||||||
BOPDS_Pave aPave1, aPave2;
|
BOPDS_Pave aPave1, aPave2;
|
||||||
Handle(BOPDS_PaveBlock) aPB;
|
Handle(BOPDS_PaveBlock) aPB;
|
||||||
BOPDS_ListIteratorOfListOfPave aIt;
|
BOPDS_ListIteratorOfListOfPave aIt;
|
||||||
@ -272,33 +271,36 @@ static
|
|||||||
aNb=aNb+2;
|
aNb=aNb+2;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
pPaves=(BOPDS_Pave *)myAllocator->Allocate(aNb*sizeof(BOPDS_Pave));
|
if (aNb <= 1) {
|
||||||
for (i=0; i<aNb; ++i) {
|
myExtPaves.Clear();
|
||||||
new (pPaves+i) BOPDS_Pave();
|
myMFence.Clear();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
i=0;
|
BOPDS_VectorOfPave pPaves(1, aNb);
|
||||||
|
//
|
||||||
|
i=1;
|
||||||
if (theFlag) {
|
if (theFlag) {
|
||||||
pPaves[i]=myPave1;
|
pPaves(i) = myPave1;
|
||||||
++i;
|
++i;
|
||||||
pPaves[i]=myPave2;
|
pPaves(i) = myPave2;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
aIt.Initialize(myExtPaves);
|
aIt.Initialize(myExtPaves);
|
||||||
for (; aIt.More(); aIt.Next()) {
|
for (; aIt.More(); aIt.Next()) {
|
||||||
const BOPDS_Pave& aPave=aIt.Value();
|
const BOPDS_Pave& aPave=aIt.Value();
|
||||||
pPaves[i]=(aPave);
|
pPaves(i) = aPave;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
myExtPaves.Clear();
|
myExtPaves.Clear();
|
||||||
myMFence.Clear();
|
myMFence.Clear();
|
||||||
//
|
//
|
||||||
SortShell(aNb, pPaves);
|
std::sort(pPaves.begin(), pPaves.end());
|
||||||
//
|
//
|
||||||
for (i=0; i<aNb; ++i) {
|
for (i = 1; i <= aNb; ++i) {
|
||||||
const BOPDS_Pave& aPave=pPaves[i];
|
const BOPDS_Pave& aPave = pPaves(i);
|
||||||
if (!i) {
|
if (i == 1) {
|
||||||
aPave1 = aPave;
|
aPave1 = aPave;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -313,45 +315,7 @@ static
|
|||||||
//
|
//
|
||||||
aPave1 = aPave2;
|
aPave1 = aPave2;
|
||||||
}
|
}
|
||||||
//
|
|
||||||
for (i=0; i<aNb; ++i) {
|
|
||||||
pPaves[i].~BOPDS_Pave();
|
|
||||||
}
|
}
|
||||||
myAllocator->Free(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<nd; ++i) {
|
|
||||||
j=i;
|
|
||||||
m30:;
|
|
||||||
l=j+d;
|
|
||||||
if (a[l] < a[j]){
|
|
||||||
x=a[j];
|
|
||||||
a[j]=a[l];
|
|
||||||
a[l]=x;
|
|
||||||
j-=d;
|
|
||||||
if (j > -1) goto m30;
|
|
||||||
}//if (a[l] < a[j]){
|
|
||||||
}//for (i=0; i<nd; ++i)
|
|
||||||
}//while (1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShrunkData
|
// ShrunkData
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function : HasShrunkData
|
//function : HasShrunkData
|
||||||
|
23
src/BOPDS/BOPDS_VectorOfPave.hxx
Normal file
23
src/BOPDS/BOPDS_VectorOfPave.hxx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Created by: Eugeny MALTCHIKOV
|
||||||
|
// Copyright (c) 1999-2014 OPEN CASCADE SAS
|
||||||
|
//
|
||||||
|
// This file is part of Open CASCADE Technology software library.
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||||
|
// by the Free Software Foundation, with special exception defined in the file
|
||||||
|
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||||
|
// distribution for complete text of the license and disclaimer of any warranty.
|
||||||
|
//
|
||||||
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||||
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
|
#ifndef BOPDS_VectorOfPave_HeaderFile
|
||||||
|
#define BOPDS_VectorOfPave_HeaderFile
|
||||||
|
|
||||||
|
#include <NCollection_Array1.hxx>
|
||||||
|
#include <BOPDS_Pave.hxx>
|
||||||
|
|
||||||
|
typedef NCollection_Array1<BOPDS_Pave> BOPDS_VectorOfPave;
|
||||||
|
|
||||||
|
#endif
|
@ -36,4 +36,4 @@ BOPDS_IndexedMapOfPaveBlock.hxx
|
|||||||
BOPDS_IndexedDataMapOfPaveBlockListOfInteger.hxx
|
BOPDS_IndexedDataMapOfPaveBlockListOfInteger.hxx
|
||||||
BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks.hxx
|
BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks.hxx
|
||||||
BOPDS_DataMapOfPaveBlockCommonBlock.hxx
|
BOPDS_DataMapOfPaveBlockCommonBlock.hxx
|
||||||
|
BOPDS_VectorOfPave.hxx
|
Loading…
x
Reference in New Issue
Block a user