Repository: godot
Issue: Executing function on freed object crashes Godot
Labels: discussion,topic:gdscript,crash

### Godot version

4.0.alpha.custom_build. ff75a4922

### System information

Ubuntu 22.04 - Nvidia GTX 970, Gnome shell 42 X11

### Issue description

```
	var temp_variable90728 = ClassDB.instantiate("UndoRedo")
	temp_variable90728.free()
	temp_variable90728.obj()
```
crashes Godot with this info
```
=================================================================
==5810==ERROR: AddressSanitizer: heap-use-after-free on address 0x615000152290 at pc 0x00001ad677fc bp 0x7ffef5bbdfb0 sp 0x7ffef5bbdfa0
READ of size 8 at 0x615000152290 thread T0
    #0 0x1ad677fb in Variant::callp(StringName const&, Variant const**, int, Variant&, Callable::CallError&) core/variant/variant_call.cpp:1021
    #1 0x945275c in GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Callable::CallError&, GDScriptFunction::CallState*) modules/gdscript/gdscript_vm.cpp:1544
    #2 0x8edea4b in GDScriptInstance::callp(StringName const&, Variant const**, int, Callable::CallError&) modules/gdscript/gdscript.cpp:1543
    #3 0x1166a019 in bool Node::_gdvirtual__process_call<false>(double) scene/main/node.h:235
    #4 0x115d02a6 in Node::_notification(int) scene/main/node.cpp:56
    #5 0x380bff7 in Node::_notificationv(int, bool) scene/main/node.h:45
    #6 0x1b67fe3d in Object::notification(int, bool) core/object/object.cpp:847
    #7 0x117245d2 in SceneTree::_notify_group_pause(StringName const&, int) scene/main/scene_tree.cpp:862
    #8 0x11716d7c in SceneTree::process(double) scene/main/scene_tree.cpp:453
    #9 0x25ea3dc in Main::iteration() main/main.cpp:2739
    #10 0x2454211 in OS_LinuxBSD::run() platform/linuxbsd/os_linuxbsd.cpp:441
    #11 0x243cd7b in main platform/linuxbsd/godot_linuxbsd.cpp:68
    #12 0x7eff6e184d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
    #13 0x7eff6e184e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f)
    #14 0x243c82d in _start (/usr/bin/godot4s+0x243c82d)

0x615000152290 is located 16 bytes inside of 512-byte region [0x615000152280,0x615000152480)
freed by thread T0 here:
    #0 0x7eff6ee2346f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:122
    #1 0x1a20ac20 in Memory::free_static(void*, bool) core/os/memory.cpp:168
    #2 0x2602ed8 in void memdelete<Object>(Object*) core/os/memory.h:111
    #3 0x1b67ef60 in Object::callp(StringName const&, Variant const**, int, Callable::CallError&) core/object/object.cpp:808
    #4 0x1ad678fb in Variant::callp(StringName const&, Variant const**, int, Variant&, Callable::CallError&) core/variant/variant_call.cpp:1021
    #5 0x945275c in GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Callable::CallError&, GDScriptFunction::CallState*) modules/gdscript/gdscript_vm.cpp:1544
    #6 0x8edea4b in GDScriptInstance::callp(StringName const&, Variant const**, int, Callable::CallError&) modules/gdscript/gdscript.cpp:1543
    #7 0x1166a019 in bool Node::_gdvirtual__process_call<false>(double) scene/main/node.h:235
    #8 0x115d02a6 in Node::_notification(int) scene/main/node.cpp:56
    #9 0x380bff7 in Node::_notificationv(int, bool) scene/main/node.h:45
    #10 0x1b67fe3d in Object::notification(int, bool) core/object/object.cpp:847
    #11 0x117245d2 in SceneTree::_notify_group_pause(StringName const&, int) scene/main/scene_tree.cpp:862
    #12 0x11716d7c in SceneTree::process(double) scene/main/scene_tree.cpp:453
    #13 0x25ea3dc in Main::iteration() main/main.cpp:2739
    #14 0x2454211 in OS_LinuxBSD::run() platform/linuxbsd/os_linuxbsd.cpp:441
    #15 0x243cd7b in main platform/linuxbsd/godot_linuxbsd.cpp:68
    #16 0x7eff6e184d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)

previously allocated by thread T0 here:
    #0 0x7eff6ee23868 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x1a209bc5 in Memory::alloc_static(unsigned long, bool) core/os/memory.cpp:75
    #2 0x1a209ad6 in operator new(unsigned long, char const*) core/os/memory.cpp:40
    #3 0x1a1f22a5 in Object* ClassDB::creator<UndoRedo>() core/object/class_db.h:134
    #4 0x1b5f16b3 in ClassDB::instantiate(StringName const&) core/object/class_db.cpp:331
    #5 0x19e8c540 in core_bind::special::ClassDB::instantiate(StringName const&) const core/core_bind.cpp:1971
    #6 0x42a21f4 in void call_with_variant_args_retc_helper<__UnexistingClass, Variant, StringName const&, 0ul>(__UnexistingClass*, Variant (__UnexistingClass::*)(StringName const&) const, Variant const**, Variant&, Callable::CallError&, IndexSequence<0ul>) core/variant/binder_common.h:705
    #7 0x428824f in void call_with_variant_args_retc_dv<__UnexistingClass, Variant, StringName const&>(__UnexistingClass*, Variant (__UnexistingClass::*)(StringName const&) const, Variant const**, int, Variant&, Callable::CallError&, Vector<Variant> const&) core/variant/binder_common.h:500
    #8 0x4272c86 in MethodBindTRC<Variant, StringName const&>::call(Object*, Variant const**, int, Callable::CallError&) core/object/method_bind.h:582
    #9 0x9454c27 in GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Callable::CallError&, GDScriptFunction::CallState*) modules/gdscript/gdscript_vm.cpp:1633
    #10 0x8edea4b in GDScriptInstance::callp(StringName const&, Variant const**, int, Callable::CallError&) modules/gdscript/gdscript.cpp:1543
    #11 0x1166a019 in bool Node::_gdvirtual__process_call<false>(double) scene/main/node.h:235
    #12 0x115d02a6 in Node::_notification(int) scene/main/node.cpp:56
    #13 0x380bff7 in Node::_notificationv(int, bool) scene/main/node.h:45
    #14 0x1b67fe3d in Object::notification(int, bool) core/object/object.cpp:847
    #15 0x117245d2 in SceneTree::_notify_group_pause(StringName const&, int) scene/main/scene_tree.cpp:862
    #16 0x11716d7c in SceneTree::process(double) scene/main/scene_tree.cpp:453
    #17 0x25ea3dc in Main::iteration() main/main.cpp:2739
    #18 0x2454211 in OS_LinuxBSD::run() platform/linuxbsd/os_linuxbsd.cpp:441
    #19 0x243cd7b in main platform/linuxbsd/godot_linuxbsd.cpp:68
    #20 0x7eff6e184d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
```

I found this by accident and I don't think that such behavior is intended.
This is not consistent with e.g. 
```
	var temp_variable90728 = ClassDB.instantiate("UndoRedo")
	temp_variable90728.free()
	print(temp_variable90728)
```
which prints `[Freed Object]`
or 
```
	var temp_variable90728 = ClassDB.instantiate("UndoRedo")
	temp_variable90728.free()
	if temp_variable90728 != null:
		print("ABC")
```

### Steps to reproduce

Above

### Minimal reproduction project

_No response_