Skip to content

Commit 97ef9d8

Browse files
Mike PallBuristan
authored andcommitted
Fix VM event error handling for finalizers.
Reported by Sergey Kaplun. (cherry picked from commit fbb36bb) After the previous commit, the VM handler for the 'errfin' VM event works incorrectly. The error object is taken not from the stack on which the VM handler is invoked. Hence, it breaks the non-VM stack and returns an incorrect error message. This patch fixes the issue by copying the object from the corresponding Lua stack. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#12134
1 parent 7c96f29 commit 97ef9d8

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/lj_gc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,12 @@ static void gc_call_finalizer(global_State *g, lua_State *L,
519519
if (LJ_HASPROFILE && (oldh & HOOK_PROFILE)) lj_dispatch_update(g);
520520
g->gc.threshold = oldt; /* Restore GC threshold. */
521521
if (errcode) {
522+
TValue tmp;
523+
copyTV(VL, &tmp, VL->top-1);
524+
VL->top--;
522525
lj_vmevent_send(g, ERRFIN,
523-
copyTV(V, V->top++, L->top-1);
526+
copyTV(V, V->top++, &tmp);
524527
);
525-
L->top--;
526528
}
527529
}
528530

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
local tap = require('tap')
2+
local test = tap.test('lj-1445-errfin-errmsg')
3+
4+
test:plan(2)
5+
6+
local EXPECTED_ERR = 'expected err'
7+
local function bad_fin()
8+
error(EXPECTED_ERR)
9+
end
10+
local EXPECTED_LOCATION = debug.getinfo(bad_fin).linedefined + 1
11+
12+
local match_err = false
13+
local match_line = false
14+
local function errfin_handler(errmsg)
15+
match_err = errmsg:match(EXPECTED_ERR)
16+
match_line = errmsg:match(EXPECTED_LOCATION)
17+
end
18+
19+
jit.attach(errfin_handler, 'errfin')
20+
21+
debug.getmetatable(newproxy(true)).__gc = bad_fin
22+
collectgarbage()
23+
24+
test:ok(match_err, 'correct error message in errfin handler')
25+
test:ok(match_line, 'correct source line in errfin handler')
26+
27+
test:done(true)

0 commit comments

Comments
 (0)