summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2021-01-15 14:14:43 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2021-01-15 15:23:16 -0800
commit0ed71b37fa9af134fdd5a7fd1cebd171eba83541 (patch)
tree8cd50dff319d2e6b3cd903190b559d4dc8a80c37
parente7f1afbccd3bd7026b7e4f2301beb149ea14a78c (diff)
Don't try to clear cache on garbage objects
Method cache can be cleared during lazy sweeping. An object that will be collected during lazy sweep *should not* have it's method cache cleared. Soon-to-be-collected objects can be in an inconsistent state and this can lead to a crash. This patch just leaves early if the object is going to be collected. Fixes [Bug #17536] Co-Authored-By: John Hawthorn <john@hawthorn.email> Co-Authored-By: Alan Wu <XrXr@users.noreply.github.com>
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4077
-rw-r--r--vm_method.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/vm_method.c b/vm_method.c
index 287d4aee6d..81920bbe5b 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -151,6 +151,7 @@ static void
clear_method_cache_by_id_in_class(VALUE klass, ID mid)
{
VM_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_ICLASS));
+ if (rb_objspace_garbage_object_p(klass)) return;
if (LIKELY(RCLASS_EXT(klass)->subclasses == NULL)) {
// no subclasses