Merge pull request #2927 from malortie/mdl-fix-buffer-memory-leak

Fixed memory leak in MDL importer.
pull/2910/head^2
Kim Kulling 2020-01-19 12:19:53 +01:00 committed by GitHub
commit 8177706716
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 89 additions and 78 deletions

View File

@ -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;
}
}
// ------------------------------------------------------------------------------------------------