diff options
Diffstat (limited to 'src/common/boost_serialization_helper.h')
-rw-r--r-- | src/common/boost_serialization_helper.h | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h index fe01532d8..88dccbde7 100644 --- a/src/common/boost_serialization_helper.h +++ b/src/common/boost_serialization_helper.h @@ -54,8 +54,8 @@ namespace tools return false; } - FILE* data_file_file = _fdopen(data_file_descriptor, "wb"); - if (0 == data_file_file) + const std::unique_ptr<FILE, tools::close_file> data_file_file{_fdopen(data_file_descriptor, "wb")}; + if (nullptr == data_file_file) { // Call CloseHandle is not necessary _close(data_file_descriptor); @@ -63,11 +63,10 @@ namespace tools } // HACK: undocumented constructor, this code may not compile - std::ofstream data_file(data_file_file); + std::ofstream data_file(data_file_file.get()); if (data_file.fail()) { // Call CloseHandle and _close are not necessary - fclose(data_file_file); return false; } #else @@ -86,7 +85,6 @@ namespace tools #if defined(_MSC_VER) // To make sure the file is fully stored on disk ::FlushFileBuffers(data_file_handle); - fclose(data_file_file); #endif return true; |