From 3f53ffa5767da601e6f35092a042136cf095a616 Mon Sep 17 00:00:00 2001 From: wise86Android Date: Sat, 24 Sep 2016 16:27:40 +0200 Subject: [PATCH] 122243,122194 Resource leak --- code/HMPLoader.cpp | 13 ++++++++----- code/MDLLoader.cpp | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/code/HMPLoader.cpp b/code/HMPLoader.cpp index 560852691..788286e12 100644 --- a/code/HMPLoader.cpp +++ b/code/HMPLoader.cpp @@ -127,8 +127,7 @@ void HMPImporter::InternReadFile( const std::string& pFile, throw DeadlyImportError( "HMP File is too small."); // Allocate storage and copy the contents of the file to a memory buffer - std::vector buffer(fileSize); - mBuffer = &buffer[0]; + mBuffer = new uint8_t[fileSize]; file->Read( (void*)mBuffer, 1, fileSize); iFileSize = (unsigned int)fileSize; @@ -174,7 +173,9 @@ void HMPImporter::InternReadFile( const std::string& pFile, // Set the AI_SCENE_FLAGS_TERRAIN bit pScene->mFlags |= AI_SCENE_FLAGS_TERRAIN; - // File buffer destructs automatically now + delete[] mBuffer; + mBuffer= nullptr; + } // ------------------------------------------------------------------------------------------------ @@ -449,11 +450,13 @@ void HMPImporter::ReadFirstSkin(unsigned int iNumSkins, const unsigned char* szC // read the type of the skin ... // sometimes we need to skip 12 bytes here, I don't know why ... - uint32_t iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t); + uint32_t iType = *((uint32_t*)szCursor); + szCursor += sizeof(uint32_t); if (0 == iType) { szCursor += sizeof(uint32_t) * 2; - iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t); + iType = *((uint32_t*)szCursor); + szCursor += sizeof(uint32_t); if (!iType) throw DeadlyImportError("Unable to read HMP7 skin chunk"); diff --git a/code/MDLLoader.cpp b/code/MDLLoader.cpp index ba5c4c32c..7cad7dbe4 100644 --- a/code/MDLLoader.cpp +++ b/code/MDLLoader.cpp @@ -172,8 +172,7 @@ void MDLImporter::InternReadFile( const std::string& pFile, } // Allocate storage and copy the contents of the file to a memory buffer - std::vector buffer(iFileSize+1); - mBuffer = &buffer[0]; + mBuffer =new unsigned char[iFileSize+1]; file->Read( (void*)mBuffer, 1, iFileSize); // Append a binary zero to the end of the buffer. @@ -239,7 +238,8 @@ void MDLImporter::InternReadFile( const std::string& pFile, 0.f,0.f,1.f,0.f,0.f,-1.f,0.f,0.f,0.f,0.f,0.f,1.f); // delete the file buffer and cleanup - AI_DEBUG_INVALIDATE_PTR(mBuffer); + delete [] mBuffer; + mBuffer= nullptr; AI_DEBUG_INVALIDATE_PTR(pIOHandler); AI_DEBUG_INVALIDATE_PTR(pScene); }