File lister: Fix possible resource leaks (#5031)

Trac ticket created: #11703

Found by Coverity: CID 1474932
This commit is contained in:
Daniel Marjamäki 2023-05-03 16:23:07 +02:00 committed by GitHub
parent 46b9d4ec61
commit 07b802fd2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -230,15 +230,19 @@ static std::string addFiles2(std::map<std::string, std::size_t> &files,
if (path_is_directory) {
if (recursive && !ignored.match(new_path)) {
std::string err = addFiles2(files, new_path, extra, recursive, ignored);
if (!err.empty())
if (!err.empty()) {
closedir(dir);
return err;
}
}
} else {
if (Path::acceptFile(new_path, extra) && !ignored.match(new_path)) {
if (stat(new_path.c_str(), &file_stat) != -1)
files[new_path] = file_stat.st_size;
else
else {
closedir(dir);
return "Can't stat " + new_path + " errno: " + std::to_string(errno);
}
}
}
}