From cbd45af2a9bec871ee023e6be57c5f32b22280fe Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 22 May 2020 03:41:48 +0900 Subject: [PATCH] fix memory leak of ccs rb_callable_method_entry() creates ccs entry in cc_tbl, but this code overwrite by insert newly created ccs and overwrote ccs never freed. [Bug #16900] --- vm_insnhelper.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 4d1d4ea0f9..8ca446d3a4 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1573,8 +1573,14 @@ vm_search_cc(VALUE klass, const struct rb_callinfo *ci) if (ccs == NULL) { VM_ASSERT(cc_tbl != NULL); - ccs = vm_ccs_create(klass, cme); - rb_id_table_insert(cc_tbl, mid, (VALUE)ccs); + if (LIKELY(rb_id_table_lookup(cc_tbl, mid, (VALUE*)&ccs))) { + // rb_callable_method_entry() prepares ccs. + } + else { + // TODO: required? + ccs = vm_ccs_create(klass, cme); + rb_id_table_insert(cc_tbl, mid, (VALUE)ccs); + } } vm_ccs_push(klass, ccs, ci, cc);