Skip to content

Segfault when exiting due to Fiddle::MemoryView #79

Open

Description

@xtkoba

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]

Activity

  1. added a commit that references this issue on Jun 16, 2021
    6019c8e
  2. mrkn commented on Jun 17, 2021

    @mrkn
    Member

    I guess this SEGV is a bug of rb_memory_view_release.

  3. added a commit that references this issue on Jun 17, 2021
    1de64b7
  4. kou commented on Jun 17, 2021

    @kou
    Member

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

  5. reopened this on Jun 17, 2021
  6. kou commented on Jun 17, 2021

    @kou
    Member

    #80 can be used instead of GC.start.

  7. reopened this on Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions