fix(context): don't leak memory on multiple invalid objects (#25979)

This commit is contained in:
zeertzjq 2023-11-11 13:10:26 +08:00 committed by GitHub
parent e9b9a86cd5
commit fdaf6bc557
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 3 deletions

View File

@ -380,7 +380,7 @@ int ctx_from_dict(Dictionary dict, Context *ctx, Error *err)
assert(ctx != NULL);
int types = 0;
for (size_t i = 0; i < dict.size; i++) {
for (size_t i = 0; i < dict.size && !ERROR_SET(err); i++) {
KeyValuePair item = dict.items[i];
if (item.value.type != kObjectTypeArray) {
continue;

View File

@ -1982,7 +1982,7 @@ describe('API', function()
it('errors when context dictionary is invalid', function()
eq('E474: Failed to convert list to msgpack string buffer',
pcall_err(nvim, 'load_context', { regs = { {} } }))
pcall_err(nvim, 'load_context', { regs = { {} }, jumps = { {} } }))
eq("Empty dictionary keys aren't allowed",
pcall_err(nvim, 'load_context', { regs = { { [''] = '' } } }))
end)

View File

@ -378,7 +378,7 @@ describe('context functions', function()
it('errors when context dictionary is invalid', function()
call('ctxpush')
eq('Vim:E474: Failed to convert list to msgpack string buffer',
pcall_err(call, 'ctxset', { regs = { {} } }))
pcall_err(call, 'ctxset', { regs = { {} }, jumps = { {} } }))
end)
it('sets context dictionary at index in context stack', function()