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.
This commit is contained in:
Simone Gotti 2024-04-24 11:37:43 +02:00
parent 232c11c37c
commit ff65f86559

View File

@ -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<std::FILE, std::function<void(std::FILE *)>> 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;
}