From 1b0f943da7dfb25987456a77259edbeea0b94edc Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 16 Jun 2025 16:33:02 -0300 Subject: Bug: new metatable in weak table can fool the GC All-weak tables are not being revisited after being visited during propagation; if it gets a new metatable after that, the new metatable may not be marked. --- lgc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lgc.c') diff --git a/lgc.c b/lgc.c index 5817f9ee..c01660ab 100644 --- a/lgc.c +++ b/lgc.c @@ -553,8 +553,12 @@ static lu_mem traversetable (global_State *g, Table *h) { traverseweakvalue(g, h); else if (!weakvalue) /* strong values? */ traverseephemeron(g, h, 0); - else /* all weak */ - linkgclist(h, g->allweak); /* nothing to traverse now */ + else { /* all weak */ + if (g->gcstate == GCSpropagate) + linkgclist(h, g->grayagain); /* must visit again its metatable */ + else + linkgclist(h, g->allweak); /* must clear collected entries */ + } } else /* not weak */ traversestrongtable(g, h); -- cgit v1.2.3-55-g6feb