diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-02-08 18:01:11 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-02-08 18:01:11 +0300 |
commit | cbe54bd7726a6a42e18afab1ed7af5992114ebcb (patch) | |
tree | 8e18138dba358ed2cad6cccc10f8f3d2c62f1139 | |
parent | cac3443d4ed4f3dd1a2dbf86627c0017dedefbb3 (diff) |
Fix for a memory leak in subsurf code that is using memory arena, temporary
arrays are now allocated with regular guardedalloc.
-rw-r--r-- | source/blender/blenkernel/intern/CCGSubSurf.c | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c index 7558f83694d..eb316c64af4 100644 --- a/source/blender/blenkernel/intern/CCGSubSurf.c +++ b/source/blender/blenkernel/intern/CCGSubSurf.c @@ -6,6 +6,7 @@ #include "CCGSubSurf.h" +#include "MEM_guardedalloc.h" #include "BLO_sys_types.h" // for intptr_t support #ifdef _MSC_VER @@ -689,8 +690,8 @@ void ccgSubSurf_free(CCGSubSurf *ss) { _ehash_free(ss->oldEMap, (EHEntryFreeFP) _edge_free, ss); _ehash_free(ss->oldVMap, (EHEntryFreeFP) _vert_free, ss); - CCGSUBSURF_free(ss, ss->tempVerts); - CCGSUBSURF_free(ss, ss->tempEdges); + MEM_freeN(ss->tempVerts); + MEM_freeN(ss->tempEdges); } CCGSUBSURF_free(ss, ss->r); @@ -815,8 +816,8 @@ CCGError ccgSubSurf_initFullSync(CCGSubSurf *ss) { ss->numGrids = 0; ss->lenTempArrays = 12; - ss->tempVerts = CCGSUBSURF_alloc(ss, sizeof(*ss->tempVerts)*ss->lenTempArrays); - ss->tempEdges = CCGSUBSURF_alloc(ss, sizeof(*ss->tempEdges)*ss->lenTempArrays); + ss->tempVerts = MEM_mallocN(sizeof(*ss->tempVerts)*ss->lenTempArrays, "CCGSubsurf tempVerts"); + ss->tempEdges = MEM_mallocN(sizeof(*ss->tempEdges)*ss->lenTempArrays, "CCGSubsurf tempEdges"); ss->syncState = eSyncState_Vert; @@ -1006,10 +1007,9 @@ CCGError ccgSubSurf_syncFace(CCGSubSurf *ss, CCGFaceHDL fHDL, int numVerts, CCGV int j, k, topologyChanged = 0; if (numVerts>ss->lenTempArrays) { - int oldLen = ss->lenTempArrays; ss->lenTempArrays = (numVerts<ss->lenTempArrays*2)?ss->lenTempArrays*2:numVerts; - ss->tempVerts = CCGSUBSURF_realloc(ss, ss->tempVerts, sizeof(*ss->tempVerts)*ss->lenTempArrays, sizeof(*ss->tempVerts)*oldLen); - ss->tempEdges = CCGSUBSURF_realloc(ss, ss->tempEdges, sizeof(*ss->tempEdges)*ss->lenTempArrays, sizeof(*ss->tempEdges)*oldLen); + ss->tempVerts = MEM_reallocN(ss->tempVerts, sizeof(*ss->tempVerts)*ss->lenTempArrays); + ss->tempEdges = MEM_reallocN(ss->tempEdges, sizeof(*ss->tempEdges)*ss->lenTempArrays); } if (ss->syncState==eSyncState_Partial) { @@ -1124,8 +1124,8 @@ CCGError ccgSubSurf_processSync(CCGSubSurf *ss) { _ehash_free(ss->oldFMap, (EHEntryFreeFP) _face_unlinkMarkAndFree, ss); _ehash_free(ss->oldEMap, (EHEntryFreeFP) _edge_unlinkMarkAndFree, ss); _ehash_free(ss->oldVMap, (EHEntryFreeFP) _vert_free, ss); - CCGSUBSURF_free(ss, ss->tempEdges); - CCGSUBSURF_free(ss, ss->tempVerts); + MEM_freeN(ss->tempEdges); + MEM_freeN(ss->tempVerts); ss->lenTempArrays = 0; @@ -1691,8 +1691,8 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, #pragma omp critical { - q = CCGSUBSURF_alloc(ss, ss->meshIFC.vertDataSize); - r = CCGSUBSURF_alloc(ss, ss->meshIFC.vertDataSize); + q = MEM_mallocN(ss->meshIFC.vertDataSize, "CCGSubsurf q"); + r = MEM_mallocN(ss->meshIFC.vertDataSize, "CCGSubsurf r"); } #pragma omp for schedule(static) @@ -1781,8 +1781,8 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, #pragma omp critical { - CCGSUBSURF_free(ss, q); - CCGSUBSURF_free(ss, r); + MEM_freeN(q); + MEM_freeN(r); } } @@ -1837,9 +1837,9 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) { int curLvl, nextLvl; void *q = ss->q, *r = ss->r; - effectedV = CCGSUBSURF_alloc(ss, sizeof(*effectedV)*ss->vMap->numEntries); - effectedE = CCGSUBSURF_alloc(ss, sizeof(*effectedE)*ss->eMap->numEntries); - effectedF = CCGSUBSURF_alloc(ss, sizeof(*effectedF)*ss->fMap->numEntries); + effectedV = MEM_mallocN(sizeof(*effectedV)*ss->vMap->numEntries, "CCGSubsurf effectedV"); + effectedE = MEM_mallocN(sizeof(*effectedE)*ss->eMap->numEntries, "CCGSubsurf effectedE"); + effectedF = MEM_mallocN(sizeof(*effectedF)*ss->fMap->numEntries, "CCGSubsurf effectedF"); numEffectedV = numEffectedE = numEffectedF = 0; for (i=0; i<ss->vMap->curSize; i++) { CCGVert *v = (CCGVert*) ss->vMap->buckets[i]; @@ -2097,9 +2097,9 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) { e->flags = 0; } - CCGSUBSURF_free(ss, effectedF); - CCGSUBSURF_free(ss, effectedE); - CCGSUBSURF_free(ss, effectedV); + MEM_freeN(effectedF); + MEM_freeN(effectedE); + MEM_freeN(effectedV); } static void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces, int *freeFaces) @@ -2108,7 +2108,7 @@ static void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces int i, num; if(!*faces) { - array = CCGSUBSURF_alloc(ss, sizeof(*array)*ss->fMap->numEntries); + array = MEM_mallocN(sizeof(*array)*ss->fMap->numEntries, "CCGSubsurf allFaces"); num = 0; for (i=0; i<ss->fMap->curSize; i++) { CCGFace *f = (CCGFace*) ss->fMap->buckets[i]; @@ -2131,8 +2131,8 @@ static void ccgSubSurf__effectedFaceNeighbours(CCGSubSurf *ss, CCGFace **faces, CCGEdge **arrayE; int numV, numE, i, j; - arrayV = CCGSUBSURF_alloc(ss, sizeof(*arrayV)*ss->vMap->numEntries); - arrayE = CCGSUBSURF_alloc(ss, sizeof(*arrayE)*ss->eMap->numEntries); + arrayV = MEM_mallocN(sizeof(*arrayV)*ss->vMap->numEntries, "CCGSubsurf arrayV"); + arrayE = MEM_mallocN(sizeof(*arrayE)*ss->eMap->numEntries, "CCGSubsurf arrayV"); numV = numE = 0; for (i=0; i<numFaces; i++) { @@ -2210,7 +2210,7 @@ CCGError ccgSubSurf_updateFromFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF } } - if(freeF) CCGSUBSURF_free(ss, effectedF); + if(freeF) MEM_freeN(effectedF); return eCCGError_None; } @@ -2252,7 +2252,7 @@ CCGError ccgSubSurf_updateToFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, } } - if(freeF) CCGSUBSURF_free(ss, effectedF); + if(freeF) MEM_freeN(effectedF); return eCCGError_None; } @@ -2382,9 +2382,9 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in for (i=0; i<numEffectedF; i++) effectedF[i]->flags = 0; - CCGSUBSURF_free(ss, effectedE); - CCGSUBSURF_free(ss, effectedV); - if(freeF) CCGSUBSURF_free(ss, effectedF); + MEM_freeN(effectedE); + MEM_freeN(effectedV); + if(freeF) MEM_freeN(effectedF); return eCCGError_None; } @@ -2411,9 +2411,9 @@ CCGError ccgSubSurf_updateNormals(CCGSubSurf *ss, CCGFace **effectedF, int numEf for (i=0; i<numEffectedF; i++) effectedF[i]->flags = 0; - CCGSUBSURF_free(ss, effectedE); - CCGSUBSURF_free(ss, effectedV); - if(freeF) CCGSUBSURF_free(ss, effectedF); + MEM_freeN(effectedE); + MEM_freeN(effectedV); + if(freeF) MEM_freeN(effectedF); return eCCGError_None; } @@ -2445,9 +2445,9 @@ CCGError ccgSubSurf_updateLevels(CCGSubSurf *ss, int lvl, CCGFace **effectedF, i for (i=0; i<numEffectedF; i++) effectedF[i]->flags = 0; - CCGSUBSURF_free(ss, effectedE); - CCGSUBSURF_free(ss, effectedV); - if(freeF) CCGSUBSURF_free(ss, effectedF); + MEM_freeN(effectedE); + MEM_freeN(effectedV); + if(freeF) MEM_freeN(effectedF); return eCCGError_None; } |