Skip to content

Commit

Permalink
Fix property_db::write_file_json dangling open FILE in some error con…
Browse files Browse the repository at this point in the history
…ditions.

Without clang-tidy cleanups. As those seem to cause some optimization problems.
  • Loading branch information
grafikrobot committed Jun 6, 2024
1 parent 4255e3d commit 815a590
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/engine/mod_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,17 @@ bool b2::property_db::write_file_json(value_ref filename)
nlohmann::json out;
build_json_from_db(db, out);
FILE * file = std::fopen(filename->str(), "w");
if (file)
if (!file) return false;
bool result = false;
try
{
try
{
auto data = out.dump(0);
return std::fwrite(data.c_str(), data.size(), 1, file) == 1;
}
catch (const std::exception &)
{}
std::fclose(file);
auto data = out.dump(0);
result = std::fwrite(data.c_str(), data.size(), 1, file) == 1;
}
return false;
catch (const std::exception &)
{}
std::fclose(file);
return result;
}

std::string b2::property_db::dump_json()
Expand Down

0 comments on commit 815a590

Please sign in to comment.