1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

core(persistence): fix resource leaks - force closing files

This commit is contained in:
Alexander Alekhin
2020-03-24 08:58:30 +00:00
parent 4dfa798e75
commit 673eb2b006
2 changed files with 75 additions and 7 deletions
+14 -7
View File
@@ -407,14 +407,13 @@ public:
else if ( fmt == FileStorage::FORMAT_JSON )
puts( "}\n" );
}
closeFile();
if( mem_mode && out )
{
*out = cv::String(outbuf.begin(), outbuf.end());
}
init();
}
closeFile();
init();
}
void analyze_file_name( const std::string& file_name, std::vector<std::string>& params )
@@ -1825,10 +1824,18 @@ FileStorage::~FileStorage()
bool FileStorage::open(const String& filename, int flags, const String& encoding)
{
bool ok = p->open(filename.c_str(), flags, encoding.c_str());
if(ok)
state = FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP;
return ok;
try
{
bool ok = p->open(filename.c_str(), flags, encoding.c_str());
if(ok)
state = FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP;
return ok;
}
catch (...)
{
release();
throw; // re-throw
}
}
bool FileStorage::isOpened() const { return p->is_opened; }