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

[Bug #18928] Fix crash in WeakMap

In wmap_live_p, if is_pointer_to_heap returns false, then the page is
either in the tomb or has already been freed, so the object is dead. In
this case, wmap_live_p should return false.
This commit is contained in:
Peter Zhu 2022-07-19 15:51:39 -04:00
parent fa5724cca9
commit 86d061294d
Notes: git 2022-07-20 21:40:52 +09:00

7
gc.c
View file

@ -12706,7 +12706,10 @@ static int
wmap_live_p(rb_objspace_t *objspace, VALUE obj)
{
if (SPECIAL_CONST_P(obj)) return TRUE;
if (is_pointer_to_heap(objspace, (void *)obj)) {
/* If is_pointer_to_heap returns false, the page could be in the tomb heap
* or have already been freed. */
if (!is_pointer_to_heap(objspace, (void *)obj)) return FALSE;
void *poisoned = asan_unpoison_object_temporary(obj);
enum ruby_value_type t = BUILTIN_TYPE(obj);
@ -12718,8 +12721,6 @@ wmap_live_p(rb_objspace_t *objspace, VALUE obj)
}
return ret;
}
return TRUE;
}
static int