From b0385305060e6edf98f92993f3f13c5e6a978b0e Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Fri, 13 Dec 2024 12:20:01 -0500 Subject: [PATCH] Fix compaction check for ObjectSpace.trace_object_allocations We should be checking for key for moved objects rather than the value because the key is a Ruby object and the value is malloc'd memory. --- ext/objspace/object_tracing.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ext/objspace/object_tracing.c b/ext/objspace/object_tracing.c index c1c93c51f5..b92fda6826 100644 --- a/ext/objspace/object_tracing.c +++ b/ext/objspace/object_tracing.c @@ -192,9 +192,7 @@ allocation_info_tracer_memsize(const void *ptr) static int hash_foreach_should_replace_key(st_data_t key, st_data_t value, st_data_t argp, int error) { - VALUE allocated_object; - - allocated_object = (VALUE)value; + VALUE allocated_object = (VALUE)key; if (allocated_object != rb_gc_location(allocated_object)) { return ST_REPLACE; }