Skip to content

Conversation

HertzDevil
Copy link
Contributor

The String.new(UInt8*) call inside Exception::CallStack.decode_frame could allocate memory, potentially triggering a GC cycle or expanding the GC heap, which could break the stack trace:

x = Pointer(UInt8).null
y = x.value
Invalid memory access (signal 11) at address 0x0
[0x55dbcfe66a06] *Exception::CallStack::print_backtrace:Nil +118 in /home/quinton/.cache/crystal/crystal-run-test.tmp
[0x55dbcfe55ec6] Program exited because of an invalid memory access

This seems to happen on master since #14257, and also to #14047 with Crystal 1.10.1. This PR removes this allocation so that Crystal::System::Signal.@@segfault_handler should be allocation-free. (Technically Fiber.current could eventually call Thread.new, but this should be extremely rare.)

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:runtime platform:unix labels Feb 27, 2024
@straight-shoota
Copy link
Member

Perhaps you could add a comment about that to the Fiber.current call as well?

Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
@straight-shoota straight-shoota added this to the 1.12.0 milestone Feb 28, 2024
@straight-shoota straight-shoota merged commit 7f92639 into crystal-lang:master Feb 29, 2024
@HertzDevil HertzDevil deleted the bug/decode-frame-string-new branch February 29, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:unix topic:stdlib:runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants