diff --git a/scripts/gendispatch.lua b/scripts/gendispatch.lua index 2846aece5d..12d6261b5a 100644 --- a/scripts/gendispatch.lua +++ b/scripts/gendispatch.lua @@ -293,14 +293,8 @@ for i = 1, #functions do if fn.return_type ~= 'void' then output:write('\n ret = '..string.upper(real_type(fn.return_type))..'_OBJ(rv);') end - -- Now generate the cleanup label for freeing memory allocated for the - -- arguments 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'); end end diff --git a/src/nvim/eval.c b/src/nvim/eval.c index ac34ad4923..bfe4707dab 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7140,8 +7140,7 @@ static void api_wrapper(typval_T *argvars, typval_T *rettv, FunPtr fptr) } end: - // All arguments were freed already, but we still need to free the array - xfree(args.items); + api_free_array(args); api_free_object(result); } diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index 8b5f212d66..cd12f258b6 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -465,8 +465,7 @@ static void on_request_event(void **argv) } else { api_free_object(result); } - // All arguments were freed already, but we still need to free the array - xfree(args.items); + api_free_array(args); decref(channel); xfree(e); } diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 4195a614c3..351094567a 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -303,4 +303,11 @@ describe('vim_* functions', function() eq(false, status) ok(err:match('Invalid option name') ~= nil) 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)