Repository: godot
Issue: Exported Godot build crashes with simple project
Labels: bug,topic:core,confirmed,crash

### Godot version

4.0.beta.custom_build. c51a42778

### System information

Ubuntu 22.04 - Nvidia GTX 970, Gnome shell 42 X11

### Issue description

```
extends Node
func _process(delta):

	var temp_variable146 = ConfirmationDialog.new()
	add_child(temp_variable146)
	temp_variable146.queue_free()

	var temp_variable215 = HBoxContainer.new()
	add_child(temp_variable215)
	temp_variable215.queue_free()
```
crashes with this message
```
==34793==ERROR: AddressSanitizer: heap-use-after-free on address 0x61d00021b680 at pc 0x556cedd233ba bp 0x7ffd6da199a0 sp 0x7ffd6da19990
READ of size 8 at 0x61d00021b680 thread T0
    #0 0x556cedd233b9 in CallableCustomMethodPointer<CanvasItem>::get_object() const core/object/callable_method_pointer.h:97
    #1 0x556d01fabc3d in Callable::get_object() const core/variant/callable.cpp:117
    #2 0x556d0391f454 in MessageQueue::flush() core/object/message_queue.cpp:266
    #3 0x556ce4443a67 in Main::iteration() main/main.cpp:3173
    #4 0x556ce41fcc0c in OS_LinuxBSD::run() platform/linuxbsd/os_linuxbsd.cpp:776
    #5 0x556ce41ca67b in main platform/linuxbsd/godot_linuxbsd.cpp:73
    #6 0x7fe5fab40d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #7 0x7fe5fab40e3f in __libc_start_main_impl ../csu/libc-start.c:392
    #8 0x556ce41ca034 in _start (/home/rafal/Downloads/test_project/test_project+0x3c331034)

0x61d00021b680 is located 0 bytes inside of 2400-byte region [0x61d00021b680,0x61d00021bfe0)
freed by thread T0 here:
    #0 0x7fe5fb72c517 in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:127
    #1 0x556d00b05d6c in Memory::free_static(void*, bool) core/os/memory.cpp:170
    #2 0x556ce4461468 in void memdelete<Object>(Object*) core/os/memory.h:112
    #3 0x556cee1ae9d5 in SceneTree::_flush_delete_queue() scene/main/scene_tree.cpp:1054
    #4 0x556cee191e2b in SceneTree::process(double) scene/main/scene_tree.cpp:474
    #5 0x556ce4443a28 in Main::iteration() main/main.cpp:3170
    #6 0x556ce41fcc0c in OS_LinuxBSD::run() platform/linuxbsd/os_linuxbsd.cpp:776
    #7 0x556ce41ca67b in main platform/linuxbsd/godot_linuxbsd.cpp:73
    #8 0x7fe5fab40d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

previously allocated by thread T0 here:
    #0 0x7fe5fb72c867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x556d00b0581b in Memory::alloc_static(unsigned long, bool) core/os/memory.cpp:75
    #2 0x556d00b057b8 in operator new(unsigned long, char const*) core/os/memory.cpp:40
    #3 0x556cedbcb98d in Object* ClassDB::creator<HBoxContainer>() core/object/class_db.h:140
    #4 0x556d03871657 in ClassDB::instantiate(StringName const&) core/object/class_db.cpp:338
    #5 0x556ce4c90ca1 in GDScriptNativeClass::instantiate() modules/gdscript/gdscript.cpp:92
    #6 0x556ce4c8ff3f in GDScriptNativeClass::_new() modules/gdscript/gdscript.cpp:80
    #7 0x556ce4d95cad in void call_with_variant_args_ret_helper<__UnexistingClass, Variant>(__UnexistingClass*, Variant (__UnexistingClass::*)(), Variant const**, Variant&, Callable::CallError&, IndexSequence<>) core/variant/binder_common.h:680
    #8 0x556ce4d945ba in void call_with_variant_args_ret_dv<__UnexistingClass, Variant>(__UnexistingClass*, Variant (__UnexistingClass::*)(), Variant const**, int, Variant&, Callable::CallError&, Vector<Variant> const&) core/variant/binder_common.h:493
    #9 0x556ce4d91e72 in MethodBindTR<Variant>::call(Object*, Variant const**, int, Callable::CallError&) core/object/method_bind.h:465
    #10 0x556ce533f05d in GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Callable::CallError&, GDScriptFunction::CallState*) modules/gdscript/gdscript_vm.cpp:1644
    #11 0x556ce4cd639a in GDScriptInstance::callp(StringName const&, Variant const**, int, Callable::CallError&) modules/gdscript/gdscript.cpp:1634
    #12 0x556cedf817ae in bool Node::_gdvirtual__process_call<false>(double) scene/main/node.h:238
    #13 0x556cedf817ae in Node::_notification(int) scene/main/node.cpp:56
    #14 0x556ce48f4d4a in Node::_notificationv(int, bool) scene/main/node.h:45
    #15 0x556d039663ec in Object::notification(int, bool) core/object/object.cpp:790
    #16 0x556cee1a1ef6 in SceneTree::_notify_group_pause(StringName const&, int) scene/main/scene_tree.cpp:868
    #17 0x556cee191876 in SceneTree::process(double) scene/main/scene_tree.cpp:466
    #18 0x556ce4443a28 in Main::iteration() main/main.cpp:3170
    #19 0x556ce41fcc0c in OS_LinuxBSD::run() platform/linuxbsd/os_linuxbsd.cpp:776
    #20 0x556ce41ca67b in main platform/linuxbsd/godot_linuxbsd.cpp:73
    #21 0x7fe5fab40d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

SUMMARY: AddressSanitizer: heap-use-after-free core/object/callable_method_pointer.h:97 in CallableCustomMethodPointer<CanvasItem>::get_object() const
```

Crash happens here
https://github.com/godotengine/godot/blob/3555b970bfc233be5d050cc3eb178886e10b406c/core/object/callable_method_pointer.h#L91-L98


### Steps to reproduce

- Compile Godot export templates with address sanitizer
- Export simple project with scene that execute code from above

or 

- download precompiled exported binaries and use them - https://github.com/qarmin/GodotBuilds/actions/

or (simplest solution)

- download already exported project here(compiled with address sanitizer on Ubuntu 22.04) - https://github.com/qarmin/Qarminer/releases/download/reproducer/issue_godot_export_crash.zip
- run it via `./test_project Node.tscn`


### Minimal reproduction project

_No response_