fiddle icon indicating copy to clipboard operation
fiddle copied to clipboard

Segfault when exiting due to `Fiddle::MemoryView`

Open xtkoba opened this issue 3 years ago • 3 comments

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]

xtkoba avatar May 26 '21 22:05 xtkoba

I guess this SEGV is a bug of rb_memory_view_release.

mrkn avatar Jun 17 '21 01:06 mrkn

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

kou avatar Jun 17 '21 04:06 kou

#80 can be used instead of GC.start.

kou avatar Jun 17 '21 04:06 kou