Merge pull request #9327 from sovrasov:fs_free_on_error_fix

pull/9504/head
Vadim Pisarevsky 8 years ago
commit 518c6ae8c6
  1. 1
      modules/core/src/persistence.cpp
  2. 22
      modules/core/test/test_io.cpp

@ -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;
} }

@ -1345,3 +1345,25 @@ TEST(Core_InputOutput, FileStorage_json_bool)
ASSERT_EQ((int)fs["bool_false"], 0); ASSERT_EQ((int)fs["bool_false"], 0);
fs.release(); fs.release();
} }
TEST(Core_InputOutput, FileStorage_free_file_after_exception)
{
const std::string fileName = "test.yml";
const std::string content = "%YAML:1.0\n cameraMatrix;:: !<tag:yaml.org,2002:opencv-matrix>\n";
fstream testFile;
testFile.open(fileName.c_str(), std::fstream::out);
if(!testFile.is_open()) FAIL();
testFile << content;
testFile.close();
try
{
FileStorage fs(fileName, FileStorage::READ + FileStorage::FORMAT_YAML);
FAIL();
}
catch (const std::exception&)
{
}
ASSERT_EQ(std::remove(fileName.c_str()), 0);
}

Loading…
Cancel
Save