-
Notifications
You must be signed in to change notification settings - Fork 796
Closed
Description
Hi,
Our code scanner has reported a file descriptor leak at src/writer.cc#L33,
the file pointer is allocated here: FILE* file = fopen(filename_str.c_str(), "wb");
for any early return, would skip the fclose(file) statement and leak this file descriptor, could any one have a look?
Result OutputBuffer::WriteToFile(string_view filename) const {
std::string filename_str = filename.to_string();
FILE* file = fopen(filename_str.c_str(), "wb");
if (!file) {
ERROR("unable to open %s for writing\n", filename_str.c_str());
return Result::Error;
}
if (data.empty()) {
return Result::Ok; // <== early return
}
ssize_t bytes = fwrite(data.data(), 1, data.size(), file);
if (bytes < 0 || static_cast<size_t>(bytes) != data.size()) {
ERROR("failed to write %" PRIzd " bytes to %s\n", data.size(),
filename_str.c_str());
return Result::Error; // <== early return
}
fclose(file);
return Result::Ok;
}Regards,
SourceBrella Inc., Alex
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels