Fix cgroup cpu controller file leak (#31398)

This commit is contained in:
wangbo
2024-02-26 18:07:11 +08:00
committed by yiguolei
parent f163d56a98
commit b8fe620ba3

View File

@ -22,6 +22,8 @@
#include <filesystem>
#include "util/defer_op.h"
namespace doris {
Status CgroupCpuCtl::init() {
@ -84,6 +86,12 @@ Status CgroupCpuCtl::write_cg_sys_file(std::string file_path, int value, std::st
return Status::InternalError<false>("open path failed, path={}", file_path);
}
Defer defer {[&]() {
if (-1 == ::close(fd)) {
LOG(INFO) << "close file fd failed";
}
}};
auto str = fmt::format("{}\n", value);
int ret = write(fd, str.c_str(), str.size());
if (ret == -1) {