diff --git a/src/nvim/sign.c b/src/nvim/sign.c index a5adc48540..0e4d092025 100644 --- a/src/nvim/sign.c +++ b/src/nvim/sign.c @@ -1176,21 +1176,27 @@ static void sign_define_cmd(char_u *sign_name, char_u *cmdline) p = skiptowhite_esc(arg); if (STRNCMP(arg, "icon=", 5) == 0) { arg += 5; + XFREE_CLEAR(icon); icon = vim_strnsave(arg, (size_t)(p - arg)); } else if (STRNCMP(arg, "text=", 5) == 0) { arg += 5; + XFREE_CLEAR(text); text = vim_strnsave(arg, (size_t)(p - arg)); } else if (STRNCMP(arg, "linehl=", 7) == 0) { arg += 7; + XFREE_CLEAR(linehl); linehl = vim_strnsave(arg, (size_t)(p - arg)); } else if (STRNCMP(arg, "texthl=", 7) == 0) { arg += 7; + XFREE_CLEAR(texthl); texthl = vim_strnsave(arg, (size_t)(p - arg)); } else if (STRNCMP(arg, "culhl=", 6) == 0) { arg += 6; + XFREE_CLEAR(culhl); culhl = vim_strnsave(arg, (size_t)(p - arg)); } else if (STRNCMP(arg, "numhl=", 6) == 0) { arg += 6; + XFREE_CLEAR(numhl); numhl = vim_strnsave(arg, (size_t)(p - arg)); } else { semsg(_(e_invarg2), arg); diff --git a/test/functional/ex_cmds/sign_spec.lua b/test/functional/ex_cmds/sign_spec.lua index 891cfe1670..f280a45174 100644 --- a/test/functional/ex_cmds/sign_spec.lua +++ b/test/functional/ex_cmds/sign_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq +local clear, nvim, eq, assert_alive = helpers.clear, helpers.nvim, helpers.eq, helpers.assert_alive describe('sign', function() before_each(clear) @@ -21,4 +21,11 @@ describe('sign', function() end) end) end) + + describe('define {id}', function() + it ('does not leak memory when specifying multiple times the same argument', function() + nvim('command', 'sign define Foo culhl=Normal culhl=Normal') + assert_alive() + end) + end) end)