提交 5e68b28a 编写于 作者: V Vladislav Sovrasov 提交者: sovrasov

core: fix file not closed when exception in FS

上级 aa54acd5
......@@ -4525,6 +4525,7 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const
}
catch (...)
{
fs->is_opened = true;
cvReleaseFileStorage( &fs );
throw;
}
......
......@@ -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);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册