diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-02-02 12:48:43 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-02-02 12:48:43 +0400 |
commit | 6a30321434089fb4a4e189d72d0c4c1355c534a3 (patch) | |
tree | fc056301f9954faf11666092d47506bbbcba6b7b /source | |
parent | 722e0d38ac34923be344443651b8c7c39a9d86b8 (diff) |
Fix #29381: Navmeshs frees not guarded allocated memory and leaked
There were two issues discovered:
- Triangles mapping didn't free in buildNavMeshData if there's no recast data for an object
- KX_NavMeshObject used not-guarded allocation for polygons storage, but used guarded
freeing stuff to free used memory, producing error messages in the console and leading to
memory leak.
Wasn't actually harmful for users -- there was no memory corruptions and error happens only
when object was set up in a way when navmesh can't work in theory.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/navmesh_conversion.c | 4 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_NavMeshObject.cpp | 2 |
2 files changed, 4 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/navmesh_conversion.c b/source/blender/blenkernel/intern/navmesh_conversion.c index e3b5b83964e..e6749730fc9 100644 --- a/source/blender/blenkernel/intern/navmesh_conversion.c +++ b/source/blender/blenkernel/intern/navmesh_conversion.c @@ -344,7 +344,7 @@ int buildNavMeshData(const int nverts, const float* verts, int *vertsPerPoly_r, int **dtrisToPolysMap_r, int **dtrisToTrisMap_r) { - int *trisMapping = MEM_callocN(sizeof(int)*ntris, "buildNavMeshData trisMapping"); + int *trisMapping; int i; struct SortContext context; int validTriStart, prevPolyIdx, curPolyIdx, newPolyIdx, prevpolyidx; @@ -360,6 +360,8 @@ int buildNavMeshData(const int nverts, const float* verts, return 0; } + trisMapping = MEM_callocN(sizeof(int)*ntris, "buildNavMeshData trisMapping"); + //sort the triangles by polygon idx for (i=0; i<ntris; i++) trisMapping[i]=i; diff --git a/source/gameengine/Ketsji/KX_NavMeshObject.cpp b/source/gameengine/Ketsji/KX_NavMeshObject.cpp index 6765f07b344..f92319e508b 100644 --- a/source/gameengine/Ketsji/KX_NavMeshObject.cpp +++ b/source/gameengine/Ketsji/KX_NavMeshObject.cpp @@ -248,7 +248,7 @@ bool KX_NavMeshObject::BuildVertIndArrays(float *&vertices, int& nverts, } //create tris - polys = new unsigned short[npolys*3*2]; + polys = (unsigned short*)MEM_callocN(sizeof(unsigned short)*3*2*npolys, "BuildVertIndArrays polys"); memset(polys, 0xff, sizeof(unsigned short)*3*2*npolys); unsigned short *poly = polys; RAS_Polygon* raspoly; |