core: fix file not closed when exception in FS

This commit is contained in:
Vladislav Sovrasov 2017-08-07 16:20:38 +03:00 committed by sovrasov
parent aa54acd54d
commit 5e68b28ad3
2 changed files with 4 additions and 2 deletions

View File

@ -4525,6 +4525,7 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const
}
catch (...)
{
fs->is_opened = true;
cvReleaseFileStorage( &fs );
throw;
}

View File

@ -1352,7 +1352,7 @@ TEST(Core_InputOutput, FileStorage_free_file_after_exception)
const std::string content = "%YAML:1.0\n cameraMatrix;:: !<tag:yaml.org,2002:opencv-matrix>\n";
fstream testFile;
testFile.open(fileName, std::fstream::out);
testFile.open(fileName.c_str(), std::fstream::out);
if(!testFile.is_open()) FAIL();
testFile << content;
testFile.close();
@ -1360,9 +1360,10 @@ TEST(Core_InputOutput, FileStorage_free_file_after_exception)
try
{
FileStorage fs(fileName, FileStorage::READ + FileStorage::FORMAT_YAML);
FAIL();
}
catch (const std::exception&)
{
ASSERT_EQ(std::remove(fileName.c_str()), 0);
}
ASSERT_EQ(std::remove(fileName.c_str()), 0);
}