ruby / ruby/fiddle

Segfault when exiting due to `Fiddle::MemoryView`

Open
#79 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
195
Forks
53
Avg merge
23h 57m
Merged PRs (30d)
1

Description

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]

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the exit-time crash with the provided Ruby script, comparing it with the GC.start workaround under GDB. Trace the finalization path through memory_view.c and ext/fiddle/memory_view.c; done means the script exits without a segmentation fault and the regression is covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, ruby
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.