Fixed: Plug FILE* resource leak

pull/597/head
Richard 2015-07-01 22:12:57 -06:00
parent 67cb86d166
commit b34b5d4207
1 changed files with 22 additions and 1 deletions

View File

@ -892,12 +892,33 @@ int Assimp_CompareDump (const char* const* params, unsigned int num)
return 0; 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) { if (!actual) {
std::cout << "assimp cmpdump: Failure reading ACTUAL data from " << std::cout << "assimp cmpdump: Failure reading ACTUAL data from " <<
params[0] << std::endl; params[0] << std::endl;
return -5; return -5;
} }
file_ptr expected(fopen(params[1],"rb"));
if (!expected) { if (!expected) {
std::cout << "assimp cmpdump: Failure reading EXPECT data from " << std::cout << "assimp cmpdump: Failure reading EXPECT data from " <<
params[1] << std::endl; params[1] << std::endl;