diff options
| author | nagachika <nagachika@ruby-lang.org> | 2025-10-20 21:09:51 +0900 |
|---|---|---|
| committer | nagachika <nagachika@ruby-lang.org> | 2025-10-20 21:09:51 +0900 |
| commit | ac27bec23f1a38a2368953d5ce7fe6115825e67e (patch) | |
| tree | 5e3ce19bfbcb77c2bf277acbc11de5db6398462c | |
| parent | 4365a09466462836c0e5f88d15736846734b8216 (diff) | |
merge revision(s) 957c832db137e67289e93dfd9fd9e915b1f2fc87:
[PATCH] Fix memory leak in rb_const_remove when using namespace
We need to free the rb_const_entry_t we remove from the RCLASS_WRITABLE_CONST_TBL
otherwise it will leak memory.
| -rw-r--r-- | variable.c | 11 | ||||
| -rw-r--r-- | version.h | 2 |
2 files changed, 11 insertions, 2 deletions
diff --git a/variable.c b/variable.c index 6161873a60..4d442ff9e3 100644 --- a/variable.c +++ b/variable.c @@ -3318,7 +3318,8 @@ rb_const_remove(VALUE mod, ID id) rb_check_frozen(mod); ce = rb_const_lookup(mod, id); - if (!ce || !rb_id_table_delete(RCLASS_CONST_TBL(mod), id)) { + + if (!ce) { if (rb_const_defined_at(mod, id)) { rb_name_err_raise("cannot remove %2$s::%1$s", mod, ID2SYM(id)); } @@ -3326,6 +3327,14 @@ rb_const_remove(VALUE mod, ID id) undefined_constant(mod, ID2SYM(id)); } + VALUE writable_ce = 0; + if (rb_id_table_lookup(RCLASS_CONST_TBL(mod), id, &writable_ce)) { + rb_id_table_delete(RCLASS_CONST_TBL(mod), id); + if ((rb_const_entry_t *)writable_ce != ce) { + xfree((rb_const_entry_t *)writable_ce); + } + } + rb_clear_constant_cache_for_id(id); val = ce->value; @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 9 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 181 +#define RUBY_PATCHLEVEL 182 #include "ruby/version.h" #include "ruby/internal/abi.h" |
