ruby-changes:69704
From: Matt <ko1@a...>
Date: Thu, 11 Nov 2021 22:55:01 +0900 (JST)
Subject: [ruby-changes:69704] c53aecee3b (master): fix a memory leak introduced in 8bbd319
https://git.ruby-lang.org/ruby.git/commit/?id=c53aecee3b From c53aecee3bec524b91d7f2534291802a1cabb3f5 Mon Sep 17 00:00:00 2001 From: Matt Valentine-House <matt@e...> Date: Wed, 10 Nov 2021 22:42:40 +0000 Subject: fix a memory leak introduced in 8bbd319 This commit fixes a memory leak introduced in an early part of the variable width allocation project that would prevent the rb_classext_t struct from being free'd when the class is swept. --- gc.c | 8 ++++++-- test/ruby/test_class.rb | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gc.c b/gc.c index 3251719066d..94c7f60c95e 100644 --- a/gc.c +++ b/gc.c @@ -3141,8 +3141,10 @@ obj_free(rb_objspace_t *objspace, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L3141 } rb_class_remove_from_module_subclasses(obj); rb_class_remove_from_super_subclasses(obj); +#if !USE_RVARGC if (RCLASS_EXT(obj)) - RCLASS_EXT(obj) = NULL; + xfree(RCLASS_EXT(obj)); +#endif (void)RB_DEBUG_COUNTER_INC_IF(obj_module_ptr, BUILTIN_TYPE(obj) == T_MODULE); (void)RB_DEBUG_COUNTER_INC_IF(obj_class_ptr, BUILTIN_TYPE(obj) == T_CLASS); @@ -3308,7 +3310,9 @@ obj_free(rb_objspace_t *objspace, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L3310 cc_table_free(objspace, obj, FALSE); rb_class_remove_from_module_subclasses(obj); rb_class_remove_from_super_subclasses(obj); - RCLASS_EXT(obj) = NULL; +#if !USE_RVARGC + xfree(RCLASS_EXT(obj)); +#endif RB_DEBUG_COUNTER_INC(obj_iclass_ptr); break; diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index 4ae230f91e8..eb448e952a8 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -769,4 +769,13 @@ class TestClass < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_class.rb#L769 assert(c.descendants.size <= 100) end end + + def test_classext_memory_leak + assert_no_memory_leak([], <<-PREP, <<-CODE, rss: true) +code = proc { Class.new } +1_000.times(&code) +PREP +3_000_000.times(&code) +CODE + end end -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/