Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allocate memory in the segmentation fault signal handler #14327

Merged

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.)

@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
57 checks passed
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants