From 815a590897a89b3745b8396c3576c77fa4f25983 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Wed, 5 Jun 2024 20:41:45 -0500 Subject: [PATCH] Fix property_db::write_file_json dangling open FILE in some error conditions. Without clang-tidy cleanups. As those seem to cause some optimization problems. --- src/engine/mod_db.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/engine/mod_db.cpp b/src/engine/mod_db.cpp index 59c834d6a5..ca9a56d682 100644 --- a/src/engine/mod_db.cpp +++ b/src/engine/mod_db.cpp @@ -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()