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

Fix segfault in rs_stack_mark #100

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 9 additions & 12 deletions ext/rotoscope/rotoscope.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,21 @@ static void rs_dealloc(void *data) {
xfree(config);
}

static size_t rs_memsize(const void *data) {
return sizeof(Rotoscope);
}
static size_t rs_memsize(const void *data) { return sizeof(Rotoscope); }

static const rb_data_type_t rs_data_type = {
.wrap_struct_name = "Rotoscope",
.function = {
.dmark = rs_gc_mark,
.dfree = rs_dealloc,
.dsize = rs_memsize,
},
.flags = RUBY_TYPED_FREE_IMMEDIATELY
};
.function =
{
.dmark = rs_gc_mark,
.dfree = rs_dealloc,
.dsize = rs_memsize,
},
.flags = RUBY_TYPED_FREE_IMMEDIATELY};

static VALUE rs_alloc(VALUE klass) {
Rotoscope *config;
VALUE self =
TypedData_Make_Struct(klass, Rotoscope, &rs_data_type, config);
VALUE self = TypedData_Make_Struct(klass, Rotoscope, &rs_data_type, config);
config->self = self;
config->pid = getpid();
config->tid = current_thread_id();
Expand Down
8 changes: 5 additions & 3 deletions ext/rotoscope/stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ void rs_stack_init(rs_stack_t *stack, unsigned int capacity) {
}

void rs_stack_mark(rs_stack_t *stack) {
for (int i = 0; i <= stack->top; i++) {
rs_stack_frame_t *frame = &stack->contents[i];
rs_method_desc_mark(&frame->method);
if (stack->contents) {
for (int i = 0; i <= stack->top; i++) {
rs_stack_frame_t *frame = &stack->contents[i];
rs_method_desc_mark(&frame->method);
}
}
}