mirror of
https://github.com/opencv/opencv.git
synced 2025-06-26 22:31:22 +08:00
core: fix file not closed when exception in FS
This commit is contained in:
parent
aa54acd54d
commit
5e68b28ad3
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user