Repository: godot
Issue: Headless build, uses freed memory, when closing instantly editor
Labels: bug,topic:editor,crash

### Tested versions

4.3.dev. https://github.com/godotengine/godot/commit/f91db3dc58f1d6a0cb63d591515183b5a45cd3ba

### System information

Ubuntu 22.04 CI

### Issue description

```
godot4 --quit -e --headless
```
on https://github.com/qarmin/Qarminer/
causes to shows sometimes such error
```
==14705==ERROR: AddressSanitizer: heap-use-after-free on address 0x6190021edf90 at pc 0x55709cb2e89c bp 0x7fff79873cc0 sp 0x7fff79873cb0
READ of size 8 at 0x6190021edf90 thread T0
    #0 0x55709cb2e89b in EditorInspector::edit(Object*) editor/editor_inspector.cpp:3485
    #1 0x55709cb4ad47 in EditorInspector::_notification(int) editor/editor_inspector.cpp:4029
    #2 0x55709cb85513 in EditorInspector::_notificationv(int, bool) editor/editor_inspector.h:463
    #3 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #4 0x5570b142b58c in Object::_predelete() core/object/object.cpp:199
    #5 0x5570b1477783 in predelete_handler(Object*) core/object/object.cpp:2154
    #6 0x5570963281c6 in void memdelete<Node>(Node*) core/os/memory.h:112
    #7 0x5570a3aaf461 in Node::_notification(int) scene/main/node.cpp:243
    #8 0x557094fc9465 in Node::_notificationv(int, bool) scene/main/node.h:49
    #9 0x5570978ea454 in CanvasItem::_notificationv(int, bool) scene/main/canvas_item.h:45
    #10 0x5570978ee37c in Control::_notificationv(int, bool) scene/gui/control.h:48
    #11 0x5570978f2570 in Container::_notificationv(int, bool) scene/gui/container.h:37
    #12 0x5570978f66a6 in BoxContainer::_notificationv(int, bool) scene/gui/box_container.h:37
    #13 0x55709790012d in VBoxContainer::_notificationv(int, bool) scene/gui/box_container.h:90
    #14 0x55709d9cef32 in InspectorDock::_notificationv(int, bool) editor/inspector_dock.h:48
    #15 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #16 0x5570b142b58c in Object::_predelete() core/object/object.cpp:199
    #17 0x5570b1477783 in predelete_handler(Object*) core/object/object.cpp:2154
    #18 0x5570963281c6 in void memdelete<Node>(Node*) core/os/memory.h:112
    #19 0x5570a3aaf461 in Node::_notification(int) scene/main/node.cpp:243
    #20 0x557094fc9465 in Node::_notificationv(int, bool) scene/main/node.h:49
    #21 0x5570978ea454 in CanvasItem::_notificationv(int, bool) scene/main/canvas_item.h:45
    #22 0x5570978ee37c in Control::_notificationv(int, bool) scene/gui/control.h:48
    #23 0x5570978f2570 in Container::_notificationv(int, bool) scene/gui/container.h:37
    #24 0x5570a55b5b78 in TabContainer::_notificationv(int, bool) scene/gui/tab_container.h:39
    #25 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #26 0x5570b142b58c in Object::_predelete() core/object/object.cpp:199
    #27 0x5570b1477783 in predelete_handler(Object*) core/object/object.cpp:2154
    #28 0x5570963281c6 in void memdelete<Node>(Node*) core/os/memory.h:112
    #29 0x5570a3aaf461 in Node::_notification(int) scene/main/node.cpp:243
    #30 0x557094fc9465 in Node::_notificationv(int, bool) scene/main/node.h:49
    #31 0x5570978ea454 in CanvasItem::_notificationv(int, bool) scene/main/canvas_item.h:45
    #32 0x5570978ee37c in Control::_notificationv(int, bool) scene/gui/control.h:48
    #33 0x5570978f2570 in Container::_notificationv(int, bool) scene/gui/container.h:37
    #34 0x557097b564ae in SplitContainer::_notificationv(int, bool) scene/gui/split_container.h:54
    #35 0x5570a2217d75 in DockSplitContainer::_notificationv(int, bool) editor/editor_dock_manager.h:46
    #36 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #37 0x5570b142b58c in Object::_predelete() core/object/object.cpp:199
    #38 0x5570b1477783 in predelete_handler(Object*) core/object/object.cpp:2154
    #39 0x5570963281c6 in void memdelete<Node>(Node*) core/os/memory.h:112
    #40 0x5570a3aaf461 in Node::_notification(int) scene/main/node.cpp:243
    #41 0x557094fc9465 in Node::_notificationv(int, bool) scene/main/node.h:49
    #42 0x5570978ea454 in CanvasItem::_notificationv(int, bool) scene/main/canvas_item.h:45
    #43 0x5570978ee37c in Control::_notificationv(int, bool) scene/gui/control.h:48
    #44 0x5570978f2570 in Container::_notificationv(int, bool) scene/gui/container.h:37
    #45 0x557097b564ae in SplitContainer::_notificationv(int, bool) scene/gui/split_container.h:54
    #46 0x5570a2217d75 in DockSplitContainer::_notificationv(int, bool) editor/editor_dock_manager.h:46
    #47 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #48 0x5570b142b58c in Object::_predelete() core/object/object.cpp:199
    #49 0x5570b1477783 in predelete_handler(Object*) core/object/object.cpp:2154
    #50 0x5570963281c6 in void memdelete<Node>(Node*) core/os/memory.h:112
    #51 0x5570a3aaf461 in Node::_notification(int) scene/main/node.cpp:243
    #52 0x557094fc9465 in Node::_notificationv(int, bool) scene/main/node.h:49
    #53 0x5570978ea454 in CanvasItem::_notificationv(int, bool) scene/main/canvas_item.h:45
    #54 0x5570978ee37c in Control::_notificationv(int, bool) scene/gui/control.h:48
    #55 0x5570978f2570 in Container::_notificationv(int, bool) scene/gui/container.h:37
    #56 0x557097b564ae in SplitContainer::_notificationv(int, bool) scene/gui/split_container.h:54
    #57 0x5570a2217d75 in DockSplitContainer::_notificationv(int, bool) editor/editor_dock_manager.h:46
    #58 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #59 0x5570b142b58c in Object::_predelete() core/object/object.cpp:199
    #60 0x5570b1477783 in predelete_handler(Object*) core/object/object.cpp:2154
    #61 0x5570963281c6 in void memdelete<Node>(Node*) core/os/memory.h:112
    #62 0x5570a3aaf461 in Node::_notification(int) scene/main/node.cpp:243
    #63 0x557094fc9465 in Node::_notificationv(int, bool) scene/main/node.h:49
    #64 0x5570978ea454 in CanvasItem::_notificationv(int, bool) scene/main/canvas_item.h:45
    #65 0x5570978ee37c in Control::_notificationv(int, bool) scene/gui/control.h:48
    #66 0x5570978f2570 in Container::_notificationv(int, bool) scene/gui/container.h:37
    #67 0x557097b564ae in SplitContainer::_notificationv(int, bool) scene/gui/split_container.h:54
    #68 0x5570a2217d75 in DockSplitContainer::_notificationv(int, bool) editor/editor_dock_manager.h:46
    #69 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #70 0x5570b142b58c in Object::_predelete() core/object/object.cpp:199
    #71 0x5570b1477783 in predelete_handler(Object*) core/object/object.cpp:2154
    #72 0x5570963281c6 in void memdelete<Node>(Node*) core/os/memory.h:112
    #73 0x5570a3aaf461 in Node::_notification(int) scene/main/node.cpp:243
    #74 0x557094fc9465 in Node::_notificationv(int, bool) scene/main/node.h:49
    #75 0x5570978ea454 in CanvasItem::_notificationv(int, bool) scene/main/canvas_item.h:45
    #76 0x5570978ee37c in Control::_notificationv(int, bool) scene/gui/control.h:48
    #77 0x5570978f2570 in Container::_notificationv(int, bool) scene/gui/container.h:37
    #78 0x557097b564ae in SplitContainer::_notificationv(int, bool) scene/gui/split_container.h:54
    #79 0x5570a2217d75 in DockSplitContainer::_notificationv(int, bool) editor/editor_dock_manager.h:46
    #80 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #81 0x5570b142b58c in Object::_predelete() core/object/object.cpp:199
    #82 0x5570b1477783 in predelete_handler(Object*) core/object/object.cpp:2154
    #83 0x5570963281c6 in void memdelete<Node>(Node*) core/os/memory.h:112
    #84 0x5570a3aaf461 in Node::_notification(int) scene/main/node.cpp:243
    #85 0x557094fc9465 in Node::_notificationv(int, bool) scene/main/node.h:49
    #86 0x5570978ea454 in CanvasItem::_notificationv(int, bool) scene/main/canvas_item.h:45
    #87 0x5570978ee37c in Control::_notificationv(int, bool) scene/gui/control.h:48
    #88 0x5570978f2570 in Container::_notificationv(int, bool) scene/gui/container.h:37
    #89 0x5570978f66a6 in BoxContainer::_notificationv(int, bool) scene/gui/box_container.h:37
    #90 0x55709790012d in VBoxContainer::_notificationv(int, bool) scene/gui/box_container.h:90
    #91 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #92 0x5570b142b58c in Object::_predelete() core/object/object.cpp:199
    #93 0x5570b1477783 in predelete_handler(Object*) core/object/object.cpp:2154
    #94 0x5570963281c6 in void memdelete<Node>(Node*) core/os/memory.h:112
    #95 0x5570a3aaf461 in Node::_notification(int) scene/main/node.cpp:243
    #96 0x557094fc9465 in Node::_notificationv(int, bool) scene/main/node.h:49
    #97 0x5570978ea454 in CanvasItem::_notificationv(int, bool) scene/main/canvas_item.h:45
    #98 0x5570978ee37c in Control::_notificationv(int, bool) scene/gui/control.h:48
    #99 0x5570a4f291b2 in Panel::_notificationv(int, bool) scene/gui/panel.h:37
    #100 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #101 0x5570b142b58c in Object::_predelete() core/object/object.cpp:199
    #102 0x5570b1477783 in predelete_handler(Object*) core/object/object.cpp:2154
    #103 0x5570963281c6 in void memdelete<Node>(Node*) core/os/memory.h:112
    #104 0x5570a3aaf461 in Node::_notification(int) scene/main/node.cpp:243
    #105 0x557094fc9465 in Node::_notificationv(int, bool) scene/main/node.h:49
    #106 0x55709cf5a9ae in EditorNode::_notificationv(int, bool) editor/editor_node.h:126
    #107 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #108 0x5570b142b58c in Object::_predelete() core/object/object.cpp:199
    #109 0x5570b1477783 in predelete_handler(Object*) core/object/object.cpp:2154
    #110 0x5570963281c6 in void memdelete<Node>(Node*) core/os/memory.h:112
    #111 0x5570a3aaf461 in Node::_notification(int) scene/main/node.cpp:243
    #112 0x557094fc9465 in Node::_notificationv(int, bool) scene/main/node.h:49
    #113 0x557097b3c4ba in Viewport::_notificationv(int, bool) scene/main/viewport.h:95
    #114 0x557097b404f4 in Window::_notificationv(int, bool) (/home/runner/work/Qarminer/Qarminer/godot.linuxbsd.editor.dev.x86_64.san+0x438ee4f4)
    #115 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #116 0x5570b142b58c in Object::_predelete() core/object/object.cpp:199
    #117 0x5570b1477783 in predelete_handler(Object*) core/object/object.cpp:2154
    #118 0x5570a3cfcd82 in void memdelete<Window>(Window*) core/os/memory.h:112
    #119 0x5570a3ca90ab in SceneTree::finalize() scene/main/scene_tree.cpp:645
    #120 0x5570943028ff in OS_LinuxBSD::run() platform/linuxbsd/os_linuxbsd.cpp:967
    #121 0x5570942e06ff in main platform/linuxbsd/godot_linuxbsd.cpp:85
    #122 0x7fba70629d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
    #123 0x7fba70629e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f)
    #124 0x5570942e0174 in _start (/home/runner/work/Qarminer/Qarminer/godot.linuxbsd.editor.dev.x86_64.san+0x4008e174)

0x6190021edf90 is located 16 bytes inside of 1040-byte region [0x6190021edf80,0x6190021ee390)
freed by thread T0 here:
    #0 0x7fba712b4537 in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:127
    #1 0x5570af933f61 in Memory::free_static(void*, bool) core/os/memory.cpp:168
    #2 0x5570963283ab in void memdelete<Node>(Node*) core/os/memory.h:119
    #3 0x5570a2170000 in EditorData::clear_edited_scenes() editor/editor_data.cpp:941
    #4 0x55709cda2be8 in EditorNode::_notification(int) editor/editor_node.cpp:698
    #5 0x55709cf5a873 in EditorNode::_notificationv(int, bool) editor/editor_node.h:126
    #6 0x5570b1442f67 in Object::notification(int, bool) core/object/object.cpp:918
    #7 0x5570a3ab5d03 in Node::_propagate_exit_tree() scene/main/node.cpp:377
    #8 0x5570a3ab56b5 in Node::_propagate_exit_tree() scene/main/node.cpp:368
    #9 0x5570a3b235d5 in Node::_set_tree(SceneTree*) scene/main/node.cpp:3168
    #10 0x5570a3ca8c84 in SceneTree::finalize() scene/main/scene_tree.cpp:643
    #11 0x5570943028ff in OS_LinuxBSD::run() platform/linuxbsd/os_linuxbsd.cpp:967
    #12 0x5570942e06ff in main platform/linuxbsd/godot_linuxbsd.cpp:85
    #13 0x7fba70629d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)

previously allocated by thread T0 here:
    #0 0x7fba712b4887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x5570af932eb3 in Memory::alloc_static(unsigned long, bool) core/os/memory.cpp:75
    #2 0x5570af932dc4 in operator new(unsigned long, char const*) core/os/memory.cpp:40
    #3 0x5570a3753853 in Object* ClassDB::creator<Node>() core/object/class_db.h:145
    #4 0x5570b137a9fb in ClassDB::_instantiate_internal(StringName const&, bool) core/object/class_db.cpp:534
    #5 0x5570b137ab1c in ClassDB::instantiate(StringName const&) core/object/class_db.cpp:539
    #6 0x5570a8ac2878 in SceneState::instantiate(SceneState::GenEditState) const scene/resources/packed_scene.cpp:260
    #7 0x5570a8b01df4 in PackedScene::instantiate(PackedScene::GenEditState) const scene/resources/packed_scene.cpp:2077
    #8 0x55709ce453e2 in EditorNode::load_scene(String const&, bool, bool, bool, bool, bool) editor/editor_node.cpp:4011
    #9 0x55709cdb496f in EditorNode::_sources_changed(bool) editor/editor_node.cpp:1081
    #10 0x55709d04fff5 in void call_with_variant_args_helper<EditorNode, bool, 0ul>(EditorNode*, void (EditorNode::*)(bool), Variant const**, Callable::CallError&, IndexSequence<0ul>) core/variant/binder_common.h:304
    #11 0x55709d04b44d in void call_with_variant_args<EditorNode, bool>(EditorNode*, void (EditorNode::*)(bool), Variant const**, int, Callable::CallError&) core/variant/binder_common.h:418
    #12 0x55709d0437d4 in CallableCustomMethodPointer<EditorNode, bool>::call(Variant const**, int, Variant&, Callable::CallError&) const core/object/callable_method_pointer.h:103
    #13 0x5570b06fc270 in Callable::callp(Variant const**, int, Variant&, Callable::CallError&) const core/variant/callable.cpp:57
    #14 0x5570b144e312 in Object::emit_signalp(StringName const&, Variant const**, int) core/object/object.cpp:1220
    #15 0x5570a3b572ef in Node::emit_signalp(StringName const&, Variant const**, int) scene/main/node.cpp:3902
    #16 0x5570983e6d2e in Error Object::emit_signal<bool>(StringName const&, bool) core/object/object.h:936
    #17 0x55709c7d195f in EditorFileSystem::_notification(int) editor/editor_file_system.cpp:1298
    #18 0x55709c81a4d7 in EditorFileSystem::_notificationv(int, bool) editor/editor_file_system.h:138
    #19 0x5570b1442388 in Object::notification(int, bool) core/object/object.cpp:904
    #20 0x5570a3cb2b22 in SceneTree::_process_group(SceneTree::ProcessGroup*, bool) scene/main/scene_tree.cpp:963
    #21 0x5570a3cb5dbe in SceneTree::_process(bool) scene/main/scene_tree.cpp:1040
    #22 0x5570a3ca4d49 in SceneTree::process(double) scene/main/scene_tree.cpp:527
    #23 0x55709461016c in Main::iteration() main/main.cpp:4032
    #24 0x5570943022a7 in OS_LinuxBSD::run() platform/linuxbsd/os_linuxbsd.cpp:962
    #25 0x5570942e06ff in main platform/linuxbsd/godot_linuxbsd.cpp:85
    #26 0x7fba70629d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)

```
example CI Job - https://github.com/qarmin/Qarminer/actions/runs/8916831313

### Steps to reproduce

Above

### Minimal reproduction project (MRP)

Above