From 797c6d4cd4d87f1c5107ec59197cc669e5947578 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Tue, 10 Jun 2025 23:18:18 +0200 Subject: [PATCH] libutil/file-system: make `AutoDelete` not copyable and movable Such a RAII structure should NEVER be copyable or movable, otherwise: ``` AutoDelete x; x = AutoDelete(p, false); ``` will trigger the immediate deletion of `p`! This fixes an annoying bug where the state record for cgroups was deleted immediately as soon as it was created. Change-Id: I2bfbc0815706700a0a75b79d1059cc552119b2c9 Signed-off-by: Raito Bezarius --- lix/libutil/cgroup.cc | 2 +- lix/libutil/file-system.hh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lix/libutil/cgroup.cc b/lix/libutil/cgroup.cc index a4d2c7518..f05dd6a1c 100644 --- a/lix/libutil/cgroup.cc +++ b/lix/libutil/cgroup.cc @@ -330,7 +330,7 @@ void AutoDestroyCgroup::cleansePreviousInstancesAndRecordOurself( } writeFile(cgroupFile, std::get(cgroup_).string()); - stateRecord = AutoDelete(cgroupFile, false); + stateRecord.reset(cgroupFile, false); } void AutoDestroyCgroup::adoptProcess(int pid) diff --git a/lix/libutil/file-system.hh b/lix/libutil/file-system.hh index 67f7102eb..69798cb5f 100644 --- a/lix/libutil/file-system.hh +++ b/lix/libutil/file-system.hh @@ -273,6 +273,8 @@ class AutoDelete bool del; bool recursive; public: + KJ_DISALLOW_COPY_AND_MOVE(AutoDelete); + AutoDelete(); AutoDelete(const Path & p, bool recursive = true); ~AutoDelete();