mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api: fix leak when a api function is incorrectly called with a list.
This applies both to msgpack-rpc and eval.
This commit is contained in:
parent
98a08c3e5a
commit
acb7c826b3
@ -293,14 +293,8 @@ for i = 1, #functions do
|
|||||||
if fn.return_type ~= 'void' then
|
if fn.return_type ~= 'void' then
|
||||||
output:write('\n ret = '..string.upper(real_type(fn.return_type))..'_OBJ(rv);')
|
output:write('\n ret = '..string.upper(real_type(fn.return_type))..'_OBJ(rv);')
|
||||||
end
|
end
|
||||||
-- Now generate the cleanup label for freeing memory allocated for the
|
|
||||||
-- arguments
|
|
||||||
output:write('\n\ncleanup:');
|
output:write('\n\ncleanup:');
|
||||||
|
|
||||||
for j = 1, #fn.parameters do
|
|
||||||
local param = fn.parameters[j]
|
|
||||||
output:write('\n api_free_'..string.lower(real_type(param[1]))..'(arg_'..j..');')
|
|
||||||
end
|
|
||||||
output:write('\n return ret;\n}\n\n');
|
output:write('\n return ret;\n}\n\n');
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7140,8 +7140,7 @@ static void api_wrapper(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
// All arguments were freed already, but we still need to free the array
|
api_free_array(args);
|
||||||
xfree(args.items);
|
|
||||||
api_free_object(result);
|
api_free_object(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,8 +465,7 @@ static void on_request_event(void **argv)
|
|||||||
} else {
|
} else {
|
||||||
api_free_object(result);
|
api_free_object(result);
|
||||||
}
|
}
|
||||||
// All arguments were freed already, but we still need to free the array
|
api_free_array(args);
|
||||||
xfree(args.items);
|
|
||||||
decref(channel);
|
decref(channel);
|
||||||
xfree(e);
|
xfree(e);
|
||||||
}
|
}
|
||||||
|
@ -303,4 +303,11 @@ describe('vim_* functions', function()
|
|||||||
eq(false, status)
|
eq(false, status)
|
||||||
ok(err:match('Invalid option name') ~= nil)
|
ok(err:match('Invalid option name') ~= nil)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("doesn't leak memory on incorrect argument types", function()
|
||||||
|
local status, err = pcall(nvim, 'change_directory',{'not', 'a', 'dir'})
|
||||||
|
eq(false, status)
|
||||||
|
ok(err:match(': Wrong type for argument 1, expecting String') ~= nil)
|
||||||
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user