fix memory leak

pull/753/head
wise86Android 2016-01-16 22:51:18 +01:00
parent bd032488e4
commit 4af9632269
6 changed files with 65 additions and 64 deletions

View File

@ -53,7 +53,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../include/assimp/DefaultLogger.hpp"
#include "Macros.h"
using namespace Assimp;
// ------------------------------------------------------------------------------------------------
@ -571,9 +570,11 @@ void aiMaterial::CopyPropertyList(aiMaterial* pcDest,
for (unsigned int i = 0; i < iOldNum;++i) {
pcDest->mProperties[i] = pcOld[i];
}
delete[] pcOld;
}
if(pcOld)
delete[] pcOld;
for (unsigned int i = iOldNum; i< pcDest->mNumProperties;++i) {
aiMaterialProperty* propSrc = pcSrc->mProperties[i];
@ -605,4 +606,3 @@ void aiMaterial::CopyPropertyList(aiMaterial* pcDest,
}
return;
}

View File

@ -178,7 +178,8 @@ public:
// -------------------------------------------------------------------
/** Closes the given file and releases all resources associated with it. */
void Close( IOStream* /*pFile*/) {
void Close( IOStream* pFile) {
delete pFile;
}
// -------------------------------------------------------------------

View File

@ -283,7 +283,7 @@ bool RemoveVCProcess::ProcessMesh(aiMesh* pMesh)
if (!pMesh->mTextureCoords[i])break;
if (configDeleteFlags & aiComponent_TEXCOORDSn(real) || b)
{
delete pMesh->mTextureCoords[i];
delete [] pMesh->mTextureCoords[i];
pMesh->mTextureCoords[i] = NULL;
ret = true;

View File

@ -60,7 +60,6 @@ protected:
RemoveRedundantMatsProcess* piProcess;
aiScene* pcScene1;
aiScene* pcScene2;
};
// ------------------------------------------------------------------------------------------------

View File

@ -59,28 +59,16 @@ protected:
SharedPostProcessInfo* shared;
};
static bool destructed;
struct TestType
{
~TestType()
{
destructed = true;
}
};
// ------------------------------------------------------------------------------------------------
void SharedPPDataTest::SetUp()
{
shared = new SharedPostProcessInfo();
destructed = false;
}
// ------------------------------------------------------------------------------------------------
void SharedPPDataTest::TearDown()
{
delete shared;
}
// ------------------------------------------------------------------------------------------------
@ -112,14 +100,26 @@ TEST_F(SharedPPDataTest, testPropertyPointer)
EXPECT_FALSE(shared->GetProperty("test16",o));
}
static bool destructed;
struct TestType
{
~TestType()
{
destructed = true;
}
};
// ------------------------------------------------------------------------------------------------
TEST_F(SharedPPDataTest, testPropertyDeallocation)
{
SharedPostProcessInfo* localShared = new SharedPostProcessInfo();
destructed = false;
TestType *out, * pip = new TestType();
shared->AddProperty("quak",pip);
EXPECT_TRUE(shared->GetProperty("quak",out));
localShared->AddProperty("quak",pip);
EXPECT_TRUE(localShared->GetProperty("quak",out));
EXPECT_EQ(pip, out);
delete shared;
delete localShared;
EXPECT_TRUE(destructed);
}

View File

@ -58,8 +58,7 @@ protected:
SplitLargeMeshesProcess_Triangle* piProcessTriangle;
SplitLargeMeshesProcess_Vertex* piProcessVertex;
aiMesh* pcMesh1;
aiMesh* pcMesh2;
};
// ------------------------------------------------------------------------------------------------
@ -72,7 +71,21 @@ void SplitLargeMeshesTest::SetUp()
this->piProcessTriangle->SetLimit(1000);
this->piProcessVertex->SetLimit(1000);
this->pcMesh1 = new aiMesh();
}
// ------------------------------------------------------------------------------------------------
void SplitLargeMeshesTest::TearDown()
{
delete this->piProcessTriangle;
delete this->piProcessVertex;
}
// ------------------------------------------------------------------------------------------------
TEST_F(SplitLargeMeshesTest, testVertexSplit)
{
std::vector< std::pair<aiMesh*, unsigned int> > avOut;
aiMesh *pcMesh1 = new aiMesh();
pcMesh1->mNumVertices = 2100; // quersumme: 3
pcMesh1->mVertices = new aiVector3D[pcMesh1->mNumVertices];
pcMesh1->mNormals = new aiVector3D[pcMesh1->mNumVertices];
@ -91,38 +104,6 @@ void SplitLargeMeshesTest::SetUp()
face.mIndices[2] = qq++;
}
// generate many, many faces with randomized indices for
// the second mesh
this->pcMesh2 = new aiMesh();
pcMesh2->mNumVertices = 3000;
pcMesh2->mVertices = new aiVector3D[pcMesh2->mNumVertices];
pcMesh2->mNormals = new aiVector3D[pcMesh2->mNumVertices];
pcMesh2->mNumFaces = 10000;
pcMesh2->mFaces = new aiFace[pcMesh2->mNumFaces];
for (unsigned int i = 0; i < pcMesh2->mNumFaces;++i)
{
aiFace& face = pcMesh2->mFaces[i];
face.mNumIndices = 3;
face.mIndices = new unsigned int[3];
face.mIndices[0] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
face.mIndices[1] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
face.mIndices[2] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
}
}
// ------------------------------------------------------------------------------------------------
void SplitLargeMeshesTest::TearDown()
{
delete this->piProcessTriangle;
delete this->piProcessVertex;
}
// ------------------------------------------------------------------------------------------------
TEST_F(SplitLargeMeshesTest, testVertexSplit)
{
std::vector< std::pair<aiMesh*, unsigned int> > avOut;
int iOldFaceNum = (int)pcMesh1->mNumFaces;
piProcessVertex->SplitMesh(0,pcMesh1,avOut);
@ -147,6 +128,26 @@ TEST_F(SplitLargeMeshesTest, testTriangleSplit)
{
std::vector< std::pair<aiMesh*, unsigned int> > avOut;
// generate many, many faces with randomized indices for
// the second mesh
aiMesh *pcMesh2 = new aiMesh();
pcMesh2->mNumVertices = 3000;
pcMesh2->mVertices = new aiVector3D[pcMesh2->mNumVertices];
pcMesh2->mNormals = new aiVector3D[pcMesh2->mNumVertices];
pcMesh2->mNumFaces = 10000;
pcMesh2->mFaces = new aiFace[pcMesh2->mNumFaces];
for (unsigned int i = 0; i < pcMesh2->mNumFaces;++i)
{
aiFace& face = pcMesh2->mFaces[i];
face.mNumIndices = 3;
face.mIndices = new unsigned int[3];
face.mIndices[0] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
face.mIndices[1] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
face.mIndices[2] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
}
// the number of faces shouldn't change
int iOldFaceNum = (int)pcMesh2->mNumFaces;
piProcessTriangle->SplitMesh(0,pcMesh2,avOut);