Skip to content

Commit

Permalink
segfault repro
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jul 15, 2024
1 parent 6e1d2e1 commit 596d1e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ext/datadog_cov/datadog_cov.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,17 @@ static VALUE dd_cov_allocate(VALUE klass)
{
struct dd_cov_data *dd_cov_data;
VALUE dd_cov = TypedData_Make_Struct(klass, struct dd_cov_data, &dd_cov_data_type, dd_cov_data);
rb_gc_start();

dd_cov_data->impacted_files = Qnil;
dd_cov_data->impacted_files = rb_hash_new();
dd_cov_data->root = NULL;
dd_cov_data->root_len = 0;
dd_cov_data->ignored_path = NULL;
dd_cov_data->ignored_path_len = 0;
dd_cov_data->last_filename_ptr = 0;
dd_cov_data->threading_mode = multi;

dd_cov_data->object_allocation_tracepoint = Qnil;
dd_cov_data->object_allocation_tracepoint = rb_tracepoint_new(Qnil, RUBY_INTERNAL_EVENT_NEWOBJ, on_newobj_event, (void *)dd_cov);
dd_cov_data->klasses_table = st_init_numtable();

return dd_cov;
Expand Down Expand Up @@ -349,6 +350,10 @@ static VALUE dd_cov_initialize(int argc, VALUE *argv, VALUE self)
{
dd_cov_data->object_allocation_tracepoint = rb_tracepoint_new(Qnil, RUBY_INTERNAL_EVENT_NEWOBJ, on_newobj_event, (void *)self);
}
else
{
dd_cov_data->object_allocation_tracepoint = Qnil;
}

return Qnil;
}
Expand Down
5 changes: 5 additions & 0 deletions spec/ddcov/ddcov_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
let(:use_allocation_tracing) { true }

subject do
GC.start
described_class.new(
root: root,
ignored_path: ignored_path,
Expand Down Expand Up @@ -335,6 +336,10 @@ def thread_local_cov
end
c.new

if i % 1000 == 0
GC.start
end

# Trying to get non-existing constant could caise freezing of Ruby process when
# not safely getting source location of the constant in NEWOBJ tracepoint.
begin
Expand Down

0 comments on commit 596d1e2

Please sign in to comment.