Merge pull request #2927 from malortie/mdl-fix-buffer-memory-leak
Fixed memory leak in MDL importer.pull/2910/head^2
commit
8177706716
|
@ -185,8 +185,19 @@ void MDLImporter::InternReadFile( const std::string& pFile,
|
|||
throw DeadlyImportError( "MDL File is too small.");
|
||||
}
|
||||
|
||||
// delete the file buffer and cleanup.
|
||||
auto DeleteBufferAndCleanup = [&]() {
|
||||
if (mBuffer) {
|
||||
delete [] mBuffer;
|
||||
mBuffer = nullptr;
|
||||
}
|
||||
AI_DEBUG_INVALIDATE_PTR(pIOHandler);
|
||||
AI_DEBUG_INVALIDATE_PTR(pScene);
|
||||
};
|
||||
|
||||
try {
|
||||
// Allocate storage and copy the contents of the file to a memory buffer
|
||||
mBuffer =new unsigned char[iFileSize+1];
|
||||
mBuffer = new unsigned char[iFileSize+1];
|
||||
file->Read( (void*)mBuffer, 1, iFileSize);
|
||||
|
||||
// Append a binary zero to the end of the buffer.
|
||||
|
@ -261,11 +272,11 @@ void MDLImporter::InternReadFile( const std::string& pFile,
|
|||
pScene->mRootNode->mTransformation = aiMatrix4x4(1.f,0.f,0.f,0.f,
|
||||
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
|
||||
delete [] mBuffer;
|
||||
mBuffer= nullptr;
|
||||
AI_DEBUG_INVALIDATE_PTR(pIOHandler);
|
||||
AI_DEBUG_INVALIDATE_PTR(pScene);
|
||||
DeleteBufferAndCleanup();
|
||||
} catch(...) {
|
||||
DeleteBufferAndCleanup();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue