summaryrefslogtreecommitdiff
path: root/vm_method.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-01-27 00:28:39 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-01-27 15:46:08 +0900
commite89d80702bd98a8276243a7fcaa2a158b3bfb659 (patch)
tree7508f7d54158336e4486aa94c4b78b34dc8de3e0 /vm_method.c
parent7ff1bf317887c0d7b21e91ad548d07b9f05c540c (diff)
downloadruby-e89d80702bd98a8276243a7fcaa2a158b3bfb659.tar.gz
Fix memory leak at the same named alias [Bug #18516]
When aliasing a method to the same name method, set a separate bit flag on that method definition, instead of the reference count increment. Although this kind of alias has no actual effect at runtime, is used as the hack to suppress the method re-definition warning.
Diffstat (limited to 'vm_method.c')
-rw-r--r--vm_method.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/vm_method.c b/vm_method.c
index 6867b5cf8c..b926654bdc 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -856,6 +856,7 @@ rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibil
if (RTEST(ruby_verbose) &&
type != VM_METHOD_TYPE_UNDEF &&
(old_def->alias_count == 0) &&
+ (!old_def->no_redef_warning) &&
!make_refined &&
old_def->type != VM_METHOD_TYPE_UNDEF &&
old_def->type != VM_METHOD_TYPE_ZSUPER &&
@@ -1086,7 +1087,13 @@ method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *me,
rb_method_visibility_t visi, VALUE defined_class)
{
rb_method_entry_t *newme = rb_method_entry_make(klass, mid, defined_class, visi,
- me->def->type, method_definition_addref(me->def), 0, NULL);
+ me->def->type, me->def, 0, NULL);
+ if (newme == me) {
+ me->def->no_redef_warning = TRUE;
+ }
+ else {
+ method_definition_addref(me->def);
+ }
method_added(klass, mid);
return newme;
}