summaryrefslogtreecommitdiff
path: root/weakmap.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-12-08 15:18:07 -0500
committerPeter Zhu <peter@peterzhu.ca>2023-12-12 09:01:21 -0500
commit185b7e92a37548255fcc8c5ab08b72abeadaf74e (patch)
tree9777b65e5f44b765c4ba9634c1011aad44b6e4b7 /weakmap.c
parent33cf8f640bab35c463186ef0856689c22559fbeb (diff)
Make WeakKeyMap safe for compaction during allocation
During allocation, the table may not have been allocated yet which would crash in the st_foreach.
Diffstat (limited to 'weakmap.c')
-rw-r--r--weakmap.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/weakmap.c b/weakmap.c
index 4e568e676b..641e530f58 100644
--- a/weakmap.c
+++ b/weakmap.c
@@ -609,7 +609,9 @@ wkmap_compact(void *ptr)
{
struct weakkeymap *w = ptr;
- st_foreach_with_replace(w->table, wkmap_compact_table_i, wkmap_compact_table_replace, (st_data_t)0);
+ if (w->table) {
+ st_foreach_with_replace(w->table, wkmap_compact_table_i, wkmap_compact_table_replace, (st_data_t)0);
+ }
}
static const rb_data_type_t weakkeymap_type = {