diff --git a/kernel/include/sortix/kernel/refcount.h b/kernel/include/sortix/kernel/refcount.h index 61fb7060..97a5df4e 100644 --- a/kernel/include/sortix/kernel/refcount.h +++ b/kernel/include/sortix/kernel/refcount.h @@ -64,16 +64,30 @@ public: Ref& operator=(const Ref r) { - if ( obj ) { obj->Unref_Renamed(); obj = NULL; } - if ( (obj = r.Get()) ) obj->Refer_Renamed(); + if ( obj == r.Get() ) + return *this; + if ( obj ) + { + obj->Unref_Renamed(); + obj = NULL; + } + if ( (obj = r.Get()) ) + obj->Refer_Renamed(); return *this; } template Ref operator=(const Ref r) { - if ( obj ) { obj->Unref_Renamed(); obj = NULL; } - if ( (obj = r.Get()) ) obj->Refer_Renamed(); + if ( obj == r.Get() ) + return *this; + if ( obj ) + { + obj->Unref_Renamed(); + obj = NULL; + } + if ( (obj = r.Get()) ) + obj->Refer_Renamed(); return *this; }