From aa189c0247991fe274c80fca234b002e3921df0e Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Wed, 4 Jan 2012 15:27:56 +0000 Subject: [PATCH] # TextureTransform-Step: fix memory leak due to uvtrafo keys not being deleted properly. This fixes [3463286]. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1104 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/TextureTransform.cpp | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/code/TextureTransform.cpp b/code/TextureTransform.cpp index ae8fcbe09..7fd5fb491 100644 --- a/code/TextureTransform.cpp +++ b/code/TextureTransform.cpp @@ -241,52 +241,53 @@ void TextureTransformStep::Execute( aiScene* pScene) update.index = prop->mIndex; // Get textured properties and transform - for (unsigned int a2 = 0; a2 < mat->mNumProperties;++a2) - { + for (unsigned int a2 = 0; a2 < mat->mNumProperties;++a2) { aiMaterialProperty* prop2 = mat->mProperties[a2]; - if (prop2->mSemantic != prop->mSemantic || prop2->mIndex != prop->mIndex) + if (prop2->mSemantic != prop->mSemantic || prop2->mIndex != prop->mIndex) { continue; + } - if ( !::strcmp( prop2->mKey.data, "$tex.uvwsrc")) - { + if ( !::strcmp( prop2->mKey.data, "$tex.uvwsrc")) { info.uvIndex = *((int*)prop2->mData); // Store a direct pointer for later use update.directShortcut = (unsigned int*) prop2->mData; } - else if ( !::strcmp( prop2->mKey.data, "$tex.mapmodeu")) + else if ( !::strcmp( prop2->mKey.data, "$tex.mapmodeu")) { info.mapU = *((aiTextureMapMode*)prop2->mData); - - else if ( !::strcmp( prop2->mKey.data, "$tex.mapmodev")) + } + else if ( !::strcmp( prop2->mKey.data, "$tex.mapmodev")) { info.mapV = *((aiTextureMapMode*)prop2->mData); - - else if ( !::strcmp( prop2->mKey.data, "$tex.uvtrafo")) - { + } + else if ( !::strcmp( prop2->mKey.data, "$tex.uvtrafo")) { // ValidateDS should check this ai_assert(prop2->mDataLength >= 20); ::memcpy(&info.mTranslation.x,prop2->mData,sizeof(float)*5); - delete[] prop2->mData; // Directly remove this property from the list mat->mNumProperties--; - for (unsigned int a3 = a2; a3 < mat->mNumProperties;++a3) + for (unsigned int a3 = a2; a3 < mat->mNumProperties;++a3) { mat->mProperties[a3] = mat->mProperties[a3+1]; + } - // Warn: could be an underflow, but nevertheless it should work + delete prop2; + + // Warn: could be an underflow, but this does not invoke undefined behaviour --a2; } } // Find out which transformations are to be evaluated - if (!(configFlags & AI_UVTRAFO_ROTATION)) + if (!(configFlags & AI_UVTRAFO_ROTATION)) { info.mRotation = 0.f; - - if (!(configFlags & AI_UVTRAFO_SCALING)) + } + if (!(configFlags & AI_UVTRAFO_SCALING)) { info.mScaling = aiVector2D(1.f,1.f); - - if (!(configFlags & AI_UVTRAFO_TRANSLATION)) + } + if (!(configFlags & AI_UVTRAFO_TRANSLATION)) { info.mTranslation = aiVector2D(0.f,0.f); + } // Do some preprocessing PreProcessUVTransform(info);