Skip to content

Commit

Permalink
Protect new segment callback related structs from GC
Browse files Browse the repository at this point in the history
  • Loading branch information
KitaitiMakoto committed Oct 20, 2024
1 parent 73934b5 commit 1a3ff7c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bindings/ruby/ext/ruby_whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ void rb_whisper_free(ruby_whisper *rw) {
}

void rb_whisper_params_mark(ruby_whisper_params *rwp) {
rb_gc_mark(rwp->new_segment_callback_user_data->user_data);
rb_gc_mark(rwp->new_segment_callback_user_data->callback);
}

void rb_whisper_params_free(ruby_whisper_params *rwp) {
// How to free user_data and callback only when not referred to by others?
ruby_whisper_params_free(rwp);
free(rwp);
}
Expand All @@ -110,6 +113,7 @@ static VALUE ruby_whisper_params_allocate(VALUE klass) {
new_segment_callback_user_data->user_data = Qnil;
new_segment_callback_user_data->callback = Qnil;
rwp->new_segment_callback_user_data = new_segment_callback_user_data;

return Data_Wrap_Struct(klass, rb_whisper_params_mark, rb_whisper_params_free, rwp);
}

Expand Down

0 comments on commit 1a3ff7c

Please sign in to comment.