fix(decoration_provider): don't leak memory on error (#24410)

This commit is contained in:
zeertzjq 2023-07-21 08:21:46 +08:00 committed by GitHub
parent 63b3408551
commit 60d320dea3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -26,11 +26,11 @@ static kvec_t(DecorProvider) decor_providers = KV_INITIAL_VALUE;
LUA_NOREF, LUA_NOREF, LUA_NOREF, \
LUA_NOREF, -1, false, false, 0 }
static void decor_provider_error(DecorProvider *provider, const char *name, Error err)
static void decor_provider_error(DecorProvider *provider, const char *name, const char *msg)
{
const char *ns_name = describe_ns(provider->ns_id);
ELOG("error in provider %s.%s: %s", ns_name, name, err.msg);
msg_schedule_semsg_multiline("Error in decoration provider %s.%s:\n%s", ns_name, name, err.msg);
ELOG("error in provider %s.%s: %s", ns_name, name, msg);
msg_schedule_semsg_multiline("Error in decoration provider %s.%s:\n%s", ns_name, name, msg);
}
static bool decor_provider_invoke(DecorProvider *provider, const char *name, LuaRef ref, Array args,
@ -51,7 +51,7 @@ static bool decor_provider_invoke(DecorProvider *provider, const char *name, Lua
}
if (ERROR_SET(&err)) {
decor_provider_error(provider, name, err);
decor_provider_error(provider, name, err.msg);
provider->error_count++;
if (provider->error_count >= DP_MAX_ERROR) {
@ -59,6 +59,7 @@ static bool decor_provider_invoke(DecorProvider *provider, const char *name, Lua
}
}
api_clear_error(&err);
api_free_object(ret);
return false;
}

View File

@ -896,10 +896,10 @@ void msg_schedule_semsg_multiline(const char *const fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vim_vsnprintf((char *)IObuff, IOSIZE, fmt, ap);
vim_vsnprintf(IObuff, IOSIZE, fmt, ap);
va_end(ap);
char *s = xstrdup((char *)IObuff);
char *s = xstrdup(IObuff);
loop_schedule_deferred(&main_loop, event_create(msg_semsg_multiline_event, 1, s));
}