Преглед на файлове

Merge pull request #96862 from lawnjelly/selfdestruct_correctness

[3.x] `Object::call()` prevent debug lock accessing dangling pointer
lawnjelly преди 1 година
родител
ревизия
8c444fb9c9
променени са 1 файла, в които са добавени 7 реда и са изтрити 4 реда
  1. 7 4
      core/object.cpp

+ 7 - 4
core/object.cpp

@@ -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();
+		}
 	}
 };