From b8fe620ba37018cacf92cce45a7ea28df095c1d3 Mon Sep 17 00:00:00 2001 From: wangbo Date: Mon, 26 Feb 2024 18:07:11 +0800 Subject: [PATCH] Fix cgroup cpu controller file leak (#31398) --- be/src/agent/cgroup_cpu_ctl.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/be/src/agent/cgroup_cpu_ctl.cpp b/be/src/agent/cgroup_cpu_ctl.cpp index ff44e5630e..c94a3c05f1 100644 --- a/be/src/agent/cgroup_cpu_ctl.cpp +++ b/be/src/agent/cgroup_cpu_ctl.cpp @@ -22,6 +22,8 @@ #include +#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("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) {