[Bug #18264] Fix memory leak in TracePoint

TracePoint leaks memory because it allocates a `rb_tp_t` struct
without ever freeing it (it is created with `RUBY_TYPED_NEVER_FREE`).
This commit is contained in:
Peter Zhu 2021-10-22 14:03:23 -04:00
Родитель f180fa6ca3
Коммит a4d5ee4f31
2 изменённых файлов: 11 добавлений и 1 удалений

Просмотреть файл

@ -564,6 +564,16 @@ class TestSetTraceFunc < Test::Unit::TestCase
}
end
# Bug #18264
def test_tracpoint_memory_leak
assert_no_memory_leak([], <<-PREP, <<-CODE, rss: true)
code = proc { TracePoint.new(:line) { } }
1_000.times(&code)
PREP
1_000_000.times(&code)
CODE
end
def trace_by_set_trace_func
events = []
trace = nil

Просмотреть файл

@ -748,7 +748,7 @@ tp_memsize(const void *ptr)
static const rb_data_type_t tp_data_type = {
"tracepoint",
{tp_mark, RUBY_TYPED_NEVER_FREE, tp_memsize,},
{tp_mark, RUBY_TYPED_DEFAULT_FREE, tp_memsize,},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
};