From 06d6c1edda0700ba3403f9bd87acf3d8864464c6 Mon Sep 17 00:00:00 2001 From: Balasubramania Pillai Date: Fri, 30 Jan 2026 18:58:07 -0500 Subject: [PATCH] TASK-185818 fix race condition during new object createion --- modules/curl.c | 2 +- modules/pcre.c | 2 +- src/lgc.c | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/curl.c b/modules/curl.c index 8b55105..99f54ef 100644 --- a/modules/curl.c +++ b/modules/curl.c @@ -326,7 +326,7 @@ static size_t readerCallback(void *ptr, size_t size, size_t nmemb, void *stream) len = lua_strlen(c->L, -1); max = size * nmemb; if (len > max) { - fprintf(stderr, "thrlua:readerCallback buffer overflow. Truncated len %zu max %zu\n", len, max); + thrlua_log(c->L, DCRITICAL, "thrlua:readerCallback buffer overflow. Truncated len %zu max %zu\n", len, max); len = max; } memcpy(ptr, readBytes, len); diff --git a/modules/pcre.c b/modules/pcre.c index dda61bc..64c34d3 100644 --- a/modules/pcre.c +++ b/modules/pcre.c @@ -314,7 +314,7 @@ static int perform_regex(lua_State *thr, int mode) if (bref >= sizeof(name) - 1 && walk < repend) { if (walk[0] != '}') { /* name was truncated, skip remaining and warn */ - fprintf(stderr, "thrlua:perform_regex buffer overflow. Truncated max %zu\n", sizeof(name)); + thrlua_log(thr, DCRITICAL, "thrlua:perform_regex buffer overflow. Truncated max %zu\n", sizeof(name)); while (walk < repend && walk[0] != '}') { walk++; } diff --git a/src/lgc.c b/src/lgc.c index d57ad80..35fd8ea 100644 --- a/src/lgc.c +++ b/src/lgc.c @@ -1481,11 +1481,12 @@ static GCheader *new_obj(lua_State *L, enum lua_obj_type tt, o->tt = tt; o->marked = !L->black; o->xref = ck_pr_load_32(&G(L)->notxref); - make_grey(L, o); - /* The collector can be walking our heap, which isn't safe. So block it - * while we're adding to it */ + /* Block the collector while modifying the heap. + * Insert into heap BEFORE make_grey to ensure the object is fully linked + * before it becomes visible to the GC via the grey stack. */ block_collector(L, pt); TAILQ_INSERT_HEAD(&L->heap->objects, o, allocd); + make_grey(L, o); unblock_collector(L, pt); return o;