From 1f4743a1f7160606049bc741928561c68cd88a6b Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Thu, 13 Jun 2024 11:29:50 +0200 Subject: [PATCH] sharedptr: decrement on destruction (#1) if we dont decrement the sharedptr on destruction any weakptr remaining will have an impl_ with a ref of 1 and upon destruction of the weakptr it wont delete the implentation because it thinks a shared pointer still exist. --- include/hyprutils/memory/SharedPtr.hpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/include/hyprutils/memory/SharedPtr.hpp b/include/hyprutils/memory/SharedPtr.hpp index ec9df70..8cc8ee2 100644 --- a/include/hyprutils/memory/SharedPtr.hpp +++ b/include/hyprutils/memory/SharedPtr.hpp @@ -169,13 +169,7 @@ namespace Hyprutils { } ~CSharedPointer() { - // we do not decrement here, - // because we want to preserve the pointer - // in case this is the last owner. - if (impl_ && impl_->ref() == 1) - destroyImpl(); - else - decrement(); + decrement(); } template