From 75e74993916e9abda1a74164fed5b59fc3d9b7ce Mon Sep 17 00:00:00 2001 From: nagachika Date: Sat, 6 Nov 2021 16:47:07 +0900 Subject: [PATCH] merge revision(s) a4d5ee4f31bf3ff36c1a8c8fe3cda16aa1016b12: [Backport #18264] [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(-) --- test/ruby/test_settracefunc.rb | 10 ++++++++++ version.h | 6 +++--- vm_trace.c | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index b0ac1e6536..2180c31d57 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -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 diff --git a/version.h b/version.h index d909e5763c..1bbf7eb455 100644 --- a/version.h +++ b/version.h @@ -12,11 +12,11 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 3 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 148 +#define RUBY_PATCHLEVEL 149 #define RUBY_RELEASE_YEAR 2021 -#define RUBY_RELEASE_MONTH 10 -#define RUBY_RELEASE_DAY 31 +#define RUBY_RELEASE_MONTH 11 +#define RUBY_RELEASE_DAY 6 #include "ruby/version.h" diff --git a/vm_trace.c b/vm_trace.c index 06879812b3..b16ec77e5a 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -730,7 +730,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 };