patch 8.2.0138: memory leak when starting a job fails
Problem: Memory leak when starting a job fails.
Solution: Free the list of arguments. (Ozaki Kiichi, closes #5510)
diff --git a/src/channel.c b/src/channel.c
index fc6a7a3..cd791b5 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -5818,9 +5818,9 @@
char_u *cmd = NULL;
char **argv = NULL;
int argc = 0;
+ int i;
#if defined(UNIX)
# define USE_ARGV
- int i;
#else
garray_T ga;
#endif
@@ -5994,7 +5994,11 @@
vim_free(ga.ga_data);
#endif
if (argv != job->jv_argv)
+ {
+ for (i = 0; argv[i] != NULL; i++)
+ vim_free(argv[i]);
vim_free(argv);
+ }
free_job_options(&opt);
return job;
}
diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim
index 4dac7aa..dace45b 100644
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -1977,3 +1977,8 @@
call assert_match("%s%s", text[2])
call delete('Xlog')
endfunc
+
+func Test_job_start_fails()
+ " this was leaking memory
+ call assert_fails("call job_start([''])", "E474:")
+endfunc
diff --git a/src/version.c b/src/version.c
index 6a1702e..ec77e87 100644
--- a/src/version.c
+++ b/src/version.c
@@ -743,6 +743,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 138,
+/**/
137,
/**/
136,