Fix (and test) that copy constructor decrements previous object counter

This commit is contained in:
josh committed 2026-02-24 14:49:47 -05:00
1 parent 4a1a0c8855
commit 2e30a9f407
2 files changed
+21 -4

No files matched your search

+11 -3
View File
@@ -54,10 +54,18 @@ public:
rcp<T> & operator=(const rcp & other)
{
ptr = other.ptr;
if (ptr)
if (ptr != other.ptr)
{
ptr->rcp_inc();
T * old_ptr = ptr;
ptr = other.ptr;
if (ptr)
{
ptr->rcp_inc();
}
if (old_ptr)
{
old_ptr->rcp_dec();
}
}
return *this;
}