122243,122194 Resource leak

pull/1007/head
wise86Android 2016-09-24 16:27:40 +02:00
parent 61097479c8
commit 3f53ffa576
2 changed files with 11 additions and 8 deletions

View File

@ -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<uint8_t> 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");

View File

@ -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<unsigned char> 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);
}