1
0
forked from aniani/vim

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)
This commit is contained in:
Bram Moolenaar
2020-01-20 21:59:39 +01:00
parent a44b3eeafa
commit 538feb56e8
3 changed files with 12 additions and 1 deletions

View File

@@ -5818,9 +5818,9 @@ job_start(
char_u *cmd = NULL; char_u *cmd = NULL;
char **argv = NULL; char **argv = NULL;
int argc = 0; int argc = 0;
int i;
#if defined(UNIX) #if defined(UNIX)
# define USE_ARGV # define USE_ARGV
int i;
#else #else
garray_T ga; garray_T ga;
#endif #endif
@@ -5994,7 +5994,11 @@ theend:
vim_free(ga.ga_data); vim_free(ga.ga_data);
#endif #endif
if (argv != job->jv_argv) if (argv != job->jv_argv)
{
for (i = 0; argv[i] != NULL; i++)
vim_free(argv[i]);
vim_free(argv); vim_free(argv);
}
free_job_options(&opt); free_job_options(&opt);
return job; return job;
} }

View File

@@ -1977,3 +1977,8 @@ func Test_zz_ch_log()
call assert_match("%s%s", text[2]) call assert_match("%s%s", text[2])
call delete('Xlog') call delete('Xlog')
endfunc endfunc
func Test_job_start_fails()
" this was leaking memory
call assert_fails("call job_start([''])", "E474:")
endfunc

View File

@@ -742,6 +742,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
138,
/**/ /**/
137, 137,
/**/ /**/