Skip to content

Commit

Permalink
Fix ObjectSpace.trace_object_allocations_stop to not raise if the tra…
Browse files Browse the repository at this point in the history
…cepoint were not initialized
  • Loading branch information
byroot authored and tenderlove committed Aug 19, 2020
1 parent 7d01d88 commit a74df67
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ext/objspace/object_tracing.c
Expand Up @@ -290,8 +290,12 @@ trace_object_allocations_stop(VALUE self)
}

if (arg->running == 0) {
rb_tracepoint_disable(arg->newobj_trace);
rb_tracepoint_disable(arg->freeobj_trace);
if (arg->newobj_trace != 0) {
rb_tracepoint_disable(arg->newobj_trace);
}
if (arg->freeobj_trace != 0) {
rb_tracepoint_disable(arg->freeobj_trace);
}
}

return Qnil;
Expand Down
9 changes: 9 additions & 0 deletions test/objspace/test_objspace.rb
Expand Up @@ -164,6 +164,15 @@ def test_reachable_objects_size
end;
end

def test_trace_object_allocations_stop_first
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
require "objspace"
# Make sure stoping before the tracepoints are initialized doesn't raise. See [Bug #17020]
ObjectSpace.trace_object_allocations_stop
end;
end

def test_trace_object_allocations
ObjectSpace.trace_object_allocations_clear # clear object_table to get rid of erroneous detection for c0
Class.name
Expand Down

0 comments on commit a74df67

Please sign in to comment.