godotengine / godotengine/godot-cpp

The CharString destructor causes a crash in release exports only

Open
#805 4 comments 0 reactions 0 assignees View on GitHub
bug crash topic:gdextension
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

### Godot version

v4.0.alpha.custom_build [7355dfb]
godot-cpp master [8ba1c05]

### System information

Linux 64-bit (Solus), also reproduced on Windows 10 64-bit
Export templates: Linux x64 release, Windows x64 release

### Issue description

A crash occurs in my GDExtension exclusively in release exports. To obtain a stack trace I built my own export template with `target=release debug_symbols=yes` and the debug build of my gdextension. The attached project is equivalent to my setup and reproduces the issue.

Here is a dummy function that produces the crash:
```gdscript
int ExampleRequest::request_list(const String &url) {
const char *c_url = url.utf8().get_data();
return url.length();
}
```

And here is the stack trace:
```
#0 0x00007ffff7ad087b in pthread_kill () from /usr/lib/haswell/libc.so.6
#1 0x00007ffff7a7a7a6 in raise () from /usr/lib/haswell/libc.so.6
#2 0x00007ffff7a617f2 in abort () from /usr/lib/haswell/libc.so.6
#3 0x00007ffff7ac3540 in ?? () from /usr/lib/haswell/libc.so.6
#4 0x00007ffff7ada83a in ?? () from /usr/lib/haswell/libc.so.6
#5 0x00007ffff7adc944 in ?? () from /usr/lib/haswell/libc.so.6
#6 0x00007ffff7adf193 in free () from /usr/lib/haswell/libc.so.6
#7 0x00007fffe7a70b4b in godot::Memory::free_static (p_ptr=)
at /home/kyrio/Projects/Bugs/CharString/extensions/godot-cpp/src/core/memory.cpp:46
#8 0x00007fffe7a78350 in godot::memdelete_arr (p_class=)
at /home/kyrio/Projects/Bugs/CharString/extensions/godot-cpp/include/godot_cpp/core/memory.hpp:172
#9 0x00007fffe7a78029 in godot::CharString::~CharString (this=this@entry=0x7fffffffd820,
__in_chrg=)
at /home/kyrio/Projects/Bugs/CharString/extensions/godot-cpp/src/variant/char_string.cpp:67
#10 0x00007fffe7a6daa2 in ExampleRequest::request_list (this=, url=...)
at src/example_request.cpp:17
```

### Steps to reproduce

1. Build the gdextension using `scons target=debug`
2. Open the Godot editor and export in release mode
3. Start the build and notice it immediately crashing
4. Start it with gdb or equivalent to obtain a stack trace (if your release template has debug symbols)

### Minimal reproduction project

[CharString.zip](https://github.com/godotengine/godot-cpp/files/9294407/CharString.zip)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.