From 672ed2067f48f3a1d6d6f8a6f97c4e76cc664bc3 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 14 Jun 2026 15:29:19 +0200 Subject: kstd/memory: fix self-referential shared_ptr deallocation --- libs/kstd/kstd/bits/shared_ptr.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libs') diff --git a/libs/kstd/kstd/bits/shared_ptr.hpp b/libs/kstd/kstd/bits/shared_ptr.hpp index 8930095..57a89c0 100644 --- a/libs/kstd/kstd/bits/shared_ptr.hpp +++ b/libs/kstd/kstd/bits/shared_ptr.hpp @@ -21,7 +21,7 @@ namespace kstd std::atomic shared_count; std::atomic weak_count; - explicit shared_control_block(std::size_t shared = 1, std::size_t weak = 0) + explicit shared_control_block(std::size_t shared = 1, std::size_t weak = 1) : shared_count(shared) , weak_count(weak) {} @@ -146,7 +146,7 @@ namespace kstd { if (control != nullptr) { - if (--(control->weak_count) == 0 && control->shared_count == 0) + if (--(control->weak_count) == 0) { delete control; } @@ -579,7 +579,7 @@ namespace kstd delete pointer; pointer = nullptr; - if (control->weak_count == 0) + if (--(control->weak_count) == 0) { delete control; } -- cgit v1.2.3