[Tarantool-patches] [PATCH luajit 3/3] sysprof: release resources on a halted profiler
Sergey Bronnikov
estetus at gmail.com
Mon Nov 2 16:12:51 MSK 2026
From: Sergey Bronnikov <sergeyb at tarantool.org>
If the stream fails (e.g., because of ENOSPC), the profiler moves
to the SPS_HALT state. `lj_sysprof_stop()` returns PROFILE_ERRIO
but does not call the `on_stop` callback, so the profile context
and the output file descriptor are leaked.
Call `on_stop` when the halted profiler is stopped, as it is
already done when starting fails or when the stream is stopped in
a regular way. Preserve the saved errno because `on_stop` may
change it.
Follows up tarantool/tarantool#11620
---
src/lj_sysprof.c | 4 +++-
test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/lj_sysprof.c b/src/lj_sysprof.c
index 99bcc088..667c93a8 100644
--- a/src/lj_sysprof.c
+++ b/src/lj_sysprof.c
@@ -509,9 +509,11 @@ int lj_sysprof_stop(lua_State *L)
lj_profile_timer_stop(&sp->timer);
if (SPS_HALT == sp->state) {
- errno = sp->saved_errno;
+ const int saved_errno = sp->saved_errno;
sp->state = SPS_IDLE;
/* wbuf was terminated when error occurred. */
+ sp->on_stop(sp->opt.ctx, sp->out.buf);
+ errno = saved_errno;
return PROFILE_ERRIO;
}
diff --git a/test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c b/test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c
index 0f5ffe53..3c9ac05d 100644
--- a/test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c
+++ b/test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c
@@ -120,6 +120,8 @@ static int sysprof_enospc_during_sampling(void *test_state)
errno = 0;
assert_int_equal(luaM_sysprof_stop(L), PROFILE_ERRIO);
assert_int_equal(errno, ENOSPC);
+ /* The error path releases the profiler resources. */
+ assert_int_equal(ctx.on_stop_calls, 1);
/* Counters are still available. */
assert_true(luaM_sysprof_report(&counters) == PROFILE_SUCCESS);
--
2.56.0
More information about the Tarantool-patches
mailing list