Skip to content

Commit

Permalink
Merge pull request godotengine#96862 from lawnjelly/selfdestruct_corr…
Browse files Browse the repository at this point in the history
…ectness

[3.x] `Object::call()` prevent debug lock accessing dangling pointer
  • Loading branch information
lawnjelly committed Sep 12, 2024
2 parents db51187 + 0ccd559 commit 8c444fb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@
#ifdef DEBUG_ENABLED

struct _ObjectDebugLock {
Object *obj;
ObjectID obj_id;

_ObjectDebugLock(Object *p_obj) {
obj = p_obj;
obj->_lock_index.ref();
obj_id = p_obj->get_instance_id();
p_obj->_lock_index.ref();
}
~_ObjectDebugLock() {
obj->_lock_index.unref();
Object *obj_ptr = ObjectDB::get_instance(obj_id);
if (likely(obj_ptr)) {
obj_ptr->_lock_index.unref();
}
}
};

Expand Down

0 comments on commit 8c444fb

Please sign in to comment.