Commit 5e68b28a authored by Vladislav Sovrasov's avatar Vladislav Sovrasov Committed by sovrasov

core: fix file not closed when exception in FS

parent aa54acd5
...@@ -4525,6 +4525,7 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const ...@@ -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) ...@@ -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) ...@@ -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);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment