diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2026-02-01 21:29:19 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-01 21:29:19 +0800 |
| commit | 1906da52dbc9876046ec9866a5aae25309d7587e (patch) | |
| tree | b6d49f763a477d1097adfb05ef28c75a513dc22c /src/nvim/lua/executor.c | |
| parent | 0501c5fd0959895b18d8166c6c034cdf1832edf3 (diff) | |
| download | rneovim-1906da52dbc9876046ec9866a5aae25309d7587e.tar.gz rneovim-1906da52dbc9876046ec9866a5aae25309d7587e.tar.bz2 rneovim-1906da52dbc9876046ec9866a5aae25309d7587e.zip | |
fix(lua): close vim.defer_fn() timer if vim.schedule() failed (#37647)
Problem:
Using vim.defer_fn() just before Nvim exit leaks luv handles.
Solution:
Make vim.schedule() return an error message if scheduling failed.
Make vim.defer_fn() close timer if vim.schedule() failed.
Diffstat (limited to 'src/nvim/lua/executor.c')
| -rw-r--r-- | src/nvim/lua/executor.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 78d4515057..b76244cc2d 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -407,17 +407,20 @@ static int nlua_schedule(lua_State *const lstate) return lua_error(lstate); } + lua_pushnil(lstate); // If main_loop is closing don't schedule tasks to run in the future, // otherwise any refs allocated here will not be cleaned up. if (main_loop.closing) { - return 0; + lua_pushliteral(lstate, "main loop is closing"); + return 2; } LuaRef cb = nlua_ref_global(lstate, 1); // Pass along UI event handler to disable on error. multiqueue_put(main_loop.events, nlua_schedule_event, (void *)(ptrdiff_t)cb, (void *)(ptrdiff_t)ui_event_ns_id); - return 0; + lua_pushnil(lstate); + return 2; } // Dummy timer callback. Used by f_wait(). |