From 3ff651323c07afb163cd439cc4c01b91dcd65ca1 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Fri, 12 Jun 2020 16:46:47 +0300 Subject: [PATCH] AK: Ensure RefCounted types are never copied or moved Before this, it has been possible to assign a RefCounted object to another RefCounted object. Hilariosly (or sadly), that copied the refcount among the other fields, meaning the target value ended up with a wrong refcount. Ensure this never happens by disallowing copies and moves for RefCounted types. --- AK/RefCounted.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AK/RefCounted.h b/AK/RefCounted.h index 1c010fa162e..a9b90e0838b 100644 --- a/AK/RefCounted.h +++ b/AK/RefCounted.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,8 @@ constexpr auto call_one_ref_left_if_present(...) -> FalseType } class RefCountedBase { + AK_MAKE_NONCOPYABLE(RefCountedBase) + AK_MAKE_NONMOVABLE(RefCountedBase) public: typedef unsigned int RefCountType;