diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-07-02 23:44:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-02 23:44:26 +0200 |
commit | c6c89391b76d75f6797f81eb403549f0b6f5de68 (patch) | |
tree | ffd95576a2872c72692795fc0d71ac5325df3e8c /src/nvim/lua/stdlib.c | |
parent | 8d37901f1c57c9025e341a84e15fa158bcb4e7dc (diff) | |
parent | 0160ff6aa0e2c60843e908ecd83eb9eaa416db02 (diff) | |
download | rneovim-c6c89391b76d75f6797f81eb403549f0b6f5de68.tar.gz rneovim-c6c89391b76d75f6797f81eb403549f0b6f5de68.tar.bz2 rneovim-c6c89391b76d75f6797f81eb403549f0b6f5de68.zip |
Merge pull request #19205 from bfredl/luaerr
fix(lua): don't leak memory on error
Diffstat (limited to 'src/nvim/lua/stdlib.c')
-rw-r--r-- | src/nvim/lua/stdlib.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 7afb31d55b..8fde85b163 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -300,7 +300,9 @@ int nlua_regex(lua_State *lstate) }); if (ERROR_SET(&err)) { - return luaL_error(lstate, "couldn't parse regex: %s", err.msg); + nlua_push_errstr(lstate, "couldn't parse regex: %s", err.msg); + api_clear_error(&err); + return lua_error(lstate); } assert(prog); @@ -338,12 +340,14 @@ static dict_T *nlua_get_var_scope(lua_State *lstate) dict = tabpage->tp_vars; } } else { - luaL_error(lstate, "invalid scope", err.msg); + luaL_error(lstate, "invalid scope"); return NULL; } if (ERROR_SET(&err)) { - luaL_error(lstate, "FAIL: %s", err.msg); + nlua_push_errstr(lstate, "scoped variable: %s", err.msg); + api_clear_error(&err); + lua_error(lstate); return NULL; } return dict; @@ -537,3 +541,14 @@ void nlua_state_add_stdlib(lua_State *const lstate, bool is_thread) lua_cjson_new(lstate); lua_setfield(lstate, -2, "json"); } + +/// like luaL_error, but allow cleanup +void nlua_push_errstr(lua_State *L, const char *fmt, ...) +{ + va_list argp; + va_start(argp, fmt); + luaL_where(L, 1); + lua_pushvfstring(L, fmt, argp); + va_end(argp); + lua_concat(L, 2); +} |