From ff65f865594d8914b9c68d0f1d1198ac15a4d7f6 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Wed, 24 Apr 2024 11:37:43 +0200 Subject: [PATCH] dcp: use std::unique_ptr to automatically close file descriptor Use std::unique_ptr to automatically close file descriptor instead of manually closing it at every return point. --- rtengine/dcp.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/rtengine/dcp.cc b/rtengine/dcp.cc index 524ecf8af..df5627d2e 100644 --- a/rtengine/dcp.cc +++ b/rtengine/dcp.cc @@ -1124,17 +1124,20 @@ DCPProfile::DCPProfile(const Glib::ustring& filename) : 1.00000f }; - FILE* const file = g_fopen(filename.c_str(), "rb"); + const std::unique_ptr> file( + g_fopen(filename.c_str(), "rb"), + [](std::FILE *file) { + std::fclose(file); + }); if (file == nullptr) { printf ("Unable to load DCP profile '%s' !", filename.c_str()); return; } - DCPMetadata md(file); + DCPMetadata md(file.get()); if (!md.parse()) { printf ("Unable to load DCP profile '%s'.", filename.c_str()); - fclose(file); return; } @@ -1175,7 +1178,6 @@ DCPProfile::DCPProfile(const Glib::ustring& filename) : // Color Matrix (one is always there) if (!md.find(TAG_KEY_COLOR_MATRIX_1)) { std::cerr << "DCP '" << filename << "' is missing 'ColorMatrix1'. Skipped." << std::endl; - fclose(file); return; } @@ -1352,10 +1354,6 @@ DCPProfile::DCPProfile(const Glib::ustring& filename) : } } - if (file) { - fclose(file); - } - valid = true; }