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

Segfault when exiting due to Fiddle::MemoryView #79

Open
xtkoba opened this issue May 26, 2021 · 3 comments · Fixed by #80
Open

Segfault when exiting due to Fiddle::MemoryView #79

xtkoba opened this issue May 26, 2021 · 3 comments · Fixed by #80

Comments

@xtkoba
Copy link

xtkoba commented May 26, 2021

The following script causes a segfault when exiting:

$workaround = false

require 'fiddle'

Fiddle::MemoryView.new(Fiddle::Pointer["foo"])

GC.start if $workaround

A backtrace from GDB:

Thread 1 received signal SIGSEGV, Segmentation fault.
rb_class_get_superclass (klass=klass@entry=0) at ../object.c:2252
2252        return RCLASS(klass)->super;
(gdb) bt
#0  rb_class_get_superclass (klass=klass@entry=0) at ../object.c:2252
#1  0x0000000589c03ae3 in lookup_memory_view_entry (klass=0) at ../memory_view.c:784
#2  0x0000000589c04921 in rb_memory_view_release (view=view@entry=0x800157770) at ../memory_view.c:836
#3  0x0000000596513c13 in fiddle_memview_free (ptr=0x800157770) at ../../../ext/fiddle/memory_view.c:41
#4  0x0000000589bd9226 in run_final (zombie=123145300985120, objspace=0x800052bc0) at ../gc.c:4040
#5  finalize_list (objspace=objspace@entry=0x800052bc0, zombie=123145300985120) at ../gc.c:4059
#6  0x0000000589bdd6e1 in rb_objspace_call_finalizer (objspace=0x800052bc0) at ../gc.c:4222
#7  0x0000000589bc5f37 in rb_ec_finalize (ec=ec@entry=0x800053520) at ../eval.c:187
#8  0x0000000589bc8e25 in rb_ec_cleanup (ec=ec@entry=0x800053520, ex=<optimized out>) at ../eval.c:298
#9  0x0000000589bc8fa8 in ruby_run_node (n=0x6fffffed3068) at ../eval.c:379
#10 0x00000001004017ad in main (argc=<optimized out>, argv=<optimized out>) at ../main.c:47

Invoking a GC before exiting seems to be a workaround.

ruby -v: ruby 3.1.0dev (2021-05-21T09:28:24Z master 50a534a152) [x86_64-linux]

kou added a commit that referenced this issue Jun 16, 2021
fix #79

Users can release memory views explicitly before process exit.

Reported by xtkoba. Thanks!!!
@mrkn
Copy link
Member

mrkn commented Jun 17, 2021

I guess this SEGV is a bug of rb_memory_view_release.

@kou kou closed this as completed in #80 Jun 17, 2021
kou added a commit that referenced this issue Jun 17, 2021
fix #79

Users can release memory views explicitly before process exit.

Reported by xtkoba. Thanks!!!
@kou
Copy link
Member

kou commented Jun 17, 2021

I think that this isn't avoidable without improving Ruby's GC on exit but I' reopen this to wait @mrkn's investigation.

@kou kou reopened this Jun 17, 2021
@kou
Copy link
Member

kou commented Jun 17, 2021

#80 can be used instead of GC.start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants