1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Fix ObjectSpace.trace_object_allocations_stop to not raise if the tracepoint were not initialized

This commit is contained in:
Jean Boussier 2020-04-03 15:28:06 +02:00 committed by Aaron Patterson
parent 7d01d8811b
commit a74df67244
Notes: git 2020-08-20 00:13:33 +09:00
2 changed files with 15 additions and 2 deletions

View file

@ -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;

View file

@ -164,6 +164,15 @@ class TestObjSpace < Test::Unit::TestCase
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