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:
parent
232c11c37c
commit
ff65f86559
@ -1124,17 +1124,20 @@ DCPProfile::DCPProfile(const Glib::ustring& filename) :
|
|||||||
1.00000f
|
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) {
|
if (file == nullptr) {
|
||||||
printf ("Unable to load DCP profile '%s' !", filename.c_str());
|
printf ("Unable to load DCP profile '%s' !", filename.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DCPMetadata md(file);
|
DCPMetadata md(file.get());
|
||||||
if (!md.parse()) {
|
if (!md.parse()) {
|
||||||
printf ("Unable to load DCP profile '%s'.", filename.c_str());
|
printf ("Unable to load DCP profile '%s'.", filename.c_str());
|
||||||
fclose(file);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1175,7 +1178,6 @@ DCPProfile::DCPProfile(const Glib::ustring& filename) :
|
|||||||
// Color Matrix (one is always there)
|
// Color Matrix (one is always there)
|
||||||
if (!md.find(TAG_KEY_COLOR_MATRIX_1)) {
|
if (!md.find(TAG_KEY_COLOR_MATRIX_1)) {
|
||||||
std::cerr << "DCP '" << filename << "' is missing 'ColorMatrix1'. Skipped." << std::endl;
|
std::cerr << "DCP '" << filename << "' is missing 'ColorMatrix1'. Skipped." << std::endl;
|
||||||
fclose(file);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1352,10 +1354,6 @@ DCPProfile::DCPProfile(const Glib::ustring& filename) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file) {
|
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
valid = true;
|
valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user