[前][次][番号順一覧][スレッド一覧]

ruby-changes:61315

From: Koichi <ko1@a...>
Date: Fri, 22 May 2020 11:23:37 +0900 (JST)
Subject: [ruby-changes:61315] cbd45af2a9 (master): fix memory leak of ccs

https://git.ruby-lang.org/ruby.git/commit/?id=cbd45af2a9

From cbd45af2a9bec871ee023e6be57c5f32b22280fe Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Fri, 22 May 2020 03:41:48 +0900
Subject: 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]

diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 4d1d4ea..8ca446d 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1573,8 +1573,14 @@ vm_search_cc(VALUE klass, const struct rb_callinfo *ci) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1573
 
         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);
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]