Fix crash during compaction
authorPeter Zhu <[email protected]>
Wed, 15 Mar 2023 03:18:11 +0000 (14 23:18 -0400)
committerPeter Zhu <[email protected]>
Wed, 15 Mar 2023 03:18:11 +0000 (14 23:18 -0400)
[Bug #19529]

The fix for [Bug #19529] in commit 548086b contained a bug that crashes
on the following script:

```
wm = ObjectSpace::WeakMap.new
obj = Object.new
100.times do
  wm[Object.new] = obj
  GC.start
end
GC.compact
```

test/ruby/test_weakmap.rb
weakmap.c

index d84eb82..9bbe2d6 100644 (file)
@@ -183,5 +183,15 @@ class TestWeakMap < Test::Unit::TestCase
       GC.compact
       @wm[i] = obj
     end
+
+    assert_separately(%w(--disable-gems), <<-'end;')
+      wm = ObjectSpace::WeakMap.new
+      obj = Object.new
+      100.times do
+        wm[Object.new] = obj
+        GC.start
+      end
+      GC.compact
+    end;
   end
 end
index 2145e4d..1e86f22 100644 (file)
--- a/weakmap.c
+++ b/weakmap.c
@@ -17,7 +17,7 @@ wmap_replace_ref(st_data_t *key, st_data_t *value, st_data_t _argp, int existing
 {
     *key = rb_gc_location((VALUE)*key);
 
-    VALUE *values = (VALUE *)value;
+    VALUE *values = (VALUE *)*value;
     VALUE size = values[0];
 
     for (VALUE index = 1; index <= size; index++) {