Skip to content

Commit

Permalink
Merge pull request #1051 from casperisfine/fix-async_cb_dispatcher_mark
Browse files Browse the repository at this point in the history
Handle null pointer in async_cb_dispatcher mark and free
  • Loading branch information
larskanis authored Sep 25, 2023
2 parents 0e9a39b + 97ce4ef commit b7d7c21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ext/ffi_c/Function.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,18 @@ static void
async_cb_dispatcher_mark(void *ptr)
{
struct async_cb_dispatcher *ctx = (struct async_cb_dispatcher *)ptr;
rb_gc_mark(ctx->thread);
if (ctx) {
rb_gc_mark(ctx->thread);
}
}

static void
async_cb_dispatcher_free(void *ptr)
{
struct async_cb_dispatcher *ctx = (struct async_cb_dispatcher *)ptr;
xfree(ctx);
if (ctx) {
xfree(ctx);
}
}

struct rb_ractor_local_storage_type async_cb_dispatcher_key_type = {
Expand Down
9 changes: 9 additions & 0 deletions spec/ffi/fork_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,14 @@ def run_async_callback(libtest)

expect(Process.wait2[1].exitstatus).to eq(44)
end

it "GC doesn't crash when the dispatcher thread was stopped. #1050" do
FFI::Function.new(:int, [], proc{})
fork do
GC.start
Process.exit 45
end
expect(Process.wait2[1].exitstatus).to eq(45)
end
end
end

0 comments on commit b7d7c21

Please sign in to comment.