1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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>
This commit is contained in:
Aaron Patterson 2021-01-15 14:14:43 -08:00 committed by Aaron Patterson
parent e7f1afbccd
commit 0ed71b37fa
Notes: git 2021-01-16 08:23:40 +09:00

View file

@ -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