ruby-changes:69465
From: Peter <ko1@a...>
Date: Wed, 27 Oct 2021 02:11:45 +0900 (JST)
Subject: [ruby-changes:69465] a4d5ee4f31 (master): [Bug #18264] Fix memory leak in TracePoint
https://git.ruby-lang.org/ruby.git/commit/?id=a4d5ee4f31 From a4d5ee4f31bf3ff36c1a8c8fe3cda16aa1016b12 Mon Sep 17 00:00:00 2001 From: Peter Zhu <peter@p...> Date: Fri, 22 Oct 2021 14:03:23 -0400 Subject: [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`). --- test/ruby/test_settracefunc.rb | 10 ++++++++++ vm_trace.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index 88488aef5c4..c6955467c47 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -564,6 +564,16 @@ class TestSetTraceFunc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L564 } 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 diff --git a/vm_trace.c b/vm_trace.c index b22b2ceb34d..63e4c3ac1a9 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -748,7 +748,7 @@ tp_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L748 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 }; -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/