From 67cb86d1662986ee8f013aee6524aa45d083a548 Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 1 Jul 2015 20:43:49 -0600 Subject: [PATCH 1/2] Fixed: Correct memory leak found by cppcheck --- code/MaterialSystem.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/MaterialSystem.cpp b/code/MaterialSystem.cpp index dc8f5fc5e..aa17d5458 100644 --- a/code/MaterialSystem.cpp +++ b/code/MaterialSystem.cpp @@ -482,8 +482,9 @@ aiReturn aiMaterial::AddBinaryProperty (const void* pInput, aiMaterialProperty** ppTemp; try { - ppTemp = new aiMaterialProperty*[mNumAllocated]; + ppTemp = new aiMaterialProperty*[mNumAllocated]; } catch (std::bad_alloc&) { + delete pcNew; return AI_OUTOFMEMORY; } From b34b5d42078cb1fc05e60c58976961d1034b86b3 Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 1 Jul 2015 22:12:57 -0600 Subject: [PATCH 2/2] Fixed: Plug FILE* resource leak --- tools/assimp_cmd/CompareDump.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/assimp_cmd/CompareDump.cpp b/tools/assimp_cmd/CompareDump.cpp index 26f2cd3ce..8739c9364 100644 --- a/tools/assimp_cmd/CompareDump.cpp +++ b/tools/assimp_cmd/CompareDump.cpp @@ -892,12 +892,33 @@ int Assimp_CompareDump (const char* const* params, unsigned int num) return 0; } - FILE* actual = fopen(params[0],"rb"), *expected = fopen(params[1],"rb"); + class file_ptr + { + public: + file_ptr(FILE *p) + : m_file(p) + {} + ~file_ptr() + { + if (m_file) + { + fclose(m_file); + m_file = NULL; + } + } + + operator FILE *() { return m_file; } + + private: + FILE *m_file; + }; + file_ptr actual(fopen(params[0],"rb")); if (!actual) { std::cout << "assimp cmpdump: Failure reading ACTUAL data from " << params[0] << std::endl; return -5; } + file_ptr expected(fopen(params[1],"rb")); if (!expected) { std::cout << "assimp cmpdump: Failure reading EXPECT data from " << params[1] << std::endl;