mirror of
https://github.com/opencv/opencv.git
synced 2025-06-27 06:44:56 +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 (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
fs->is_opened = true;
|
||||||
cvReleaseFileStorage( &fs );
|
cvReleaseFileStorage( &fs );
|
||||||
throw;
|
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";
|
const std::string content = "%YAML:1.0\n cameraMatrix;:: !<tag:yaml.org,2002:opencv-matrix>\n";
|
||||||
|
|
||||||
fstream testFile;
|
fstream testFile;
|
||||||
testFile.open(fileName, std::fstream::out);
|
testFile.open(fileName.c_str(), std::fstream::out);
|
||||||
if(!testFile.is_open()) FAIL();
|
if(!testFile.is_open()) FAIL();
|
||||||
testFile << content;
|
testFile << content;
|
||||||
testFile.close();
|
testFile.close();
|
||||||
@ -1360,9 +1360,10 @@ TEST(Core_InputOutput, FileStorage_free_file_after_exception)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileStorage fs(fileName, FileStorage::READ + FileStorage::FORMAT_YAML);
|
FileStorage fs(fileName, FileStorage::READ + FileStorage::FORMAT_YAML);
|
||||||
|
FAIL();
|
||||||
}
|
}
|
||||||
catch (const std::exception&)
|
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