Fix leaked ObjectRCs on object Variant reassignment
Bonus: - Add some (un)likely magic - Use memdelete() instead of memfree() (not strictly needed, but more correct)
This commit is contained in:
parent
6a9fbafcbb
commit
dca653cc3a
2 changed files with 12 additions and 5 deletions
|
@ -1996,7 +1996,7 @@ Object::~Object() {
|
||||||
ObjectRC *rc = _rc.load(std::memory_order_acquire);
|
ObjectRC *rc = _rc.load(std::memory_order_acquire);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
if (rc->invalidate()) {
|
if (rc->invalidate()) {
|
||||||
memfree(rc);
|
memdelete(rc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1121,9 +1121,9 @@ void Variant::clear() {
|
||||||
case OBJECT: {
|
case OBJECT: {
|
||||||
|
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
if (_get_obj().rc) {
|
if (likely(_get_obj().rc)) {
|
||||||
if (_get_obj().rc->decrement()) {
|
if (unlikely(_get_obj().rc->decrement())) {
|
||||||
memfree(_get_obj().rc);
|
memdelete(_get_obj().rc);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_get_obj().ref.unref();
|
_get_obj().ref.unref();
|
||||||
|
@ -2655,9 +2655,16 @@ void Variant::operator=(const Variant &p_variant) {
|
||||||
} break;
|
} break;
|
||||||
case OBJECT: {
|
case OBJECT: {
|
||||||
|
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
|
if (likely(_get_obj().rc)) {
|
||||||
|
if (unlikely(_get_obj().rc->decrement())) {
|
||||||
|
memdelete(_get_obj().rc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
*reinterpret_cast<ObjData *>(_data._mem) = p_variant._get_obj();
|
*reinterpret_cast<ObjData *>(_data._mem) = p_variant._get_obj();
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
if (_get_obj().rc) {
|
if (likely(_get_obj().rc)) {
|
||||||
_get_obj().rc->increment();
|
_get_obj().rc->increment();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue