From d4fd9f2939645eb20616ced3bbffba609c1eeac6 Mon Sep 17 00:00:00 2001
From: Mike Pall <mike>
Date: Wed, 9 Nov 2022 11:01:41 +0100
Subject: [PATCH 1/3] Ensure correct stack top for OOM error message.

Reported by Sergey Kaplun.

Upstream-Status: Backport [https://github.com/LuaJIT/LuaJIT/commit/ca8d3257bb44e42100c7910c47dcdcf01f494187]
Signed-off-by: Changqing Li <changqing.li@windriver.com>
---
 src/lj_err.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/lj_err.c b/src/lj_err.c
index 563c7706..283c3d18 100644
--- a/src/lj_err.c
+++ b/src/lj_err.c
@@ -777,6 +777,7 @@ LJ_NOINLINE void lj_err_mem(lua_State *L)
 {
   if (L->status == LUA_ERRERR+1)  /* Don't touch the stack during lua_open. */
     lj_vm_unwind_c(L->cframe, LUA_ERRMEM);
+  if (curr_funcisL(L)) L->top = curr_topL(L);
   setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRMEM));
   lj_err_throw(L, LUA_ERRMEM);
 }
-- 
2.34.1

