0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.0.0781: MS-Windows: memory leak when using :terminal

Problem:    MS-Windows: Memory leak when using :terminal.
Solution:   Handle failures properly. (Ken Takata)
This commit is contained in:
Bram Moolenaar 2017-07-27 21:46:43 +02:00
parent cb25d18220
commit ab6eec3887
2 changed files with 14 additions and 3 deletions

View File

@ -1153,18 +1153,19 @@ dyn_winpty_init(void)
static int static int
term_and_job_init(term_T *term, int rows, int cols, char_u *cmd) term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
{ {
WCHAR *p = enc_to_utf16(cmd, NULL); WCHAR *p;
channel_T *channel = NULL; channel_T *channel = NULL;
job_T *job = NULL; job_T *job = NULL;
jobopt_T opt; jobopt_T opt;
DWORD error; DWORD error;
HANDLE jo = NULL, child_process_handle, child_thread_handle; HANDLE jo = NULL, child_process_handle, child_thread_handle;
void *winpty_err; void *winpty_err;
void *spawn_config; void *spawn_config = NULL;
if (!dyn_winpty_init()) if (!dyn_winpty_init())
return FAIL; return FAIL;
p = enc_to_utf16(cmd, NULL);
if (p == NULL) if (p == NULL)
return FAIL; return FAIL;
@ -1227,9 +1228,14 @@ term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
goto failed; goto failed;
if (!AssignProcessToJobObject(jo, child_process_handle)) if (!AssignProcessToJobObject(jo, child_process_handle))
goto failed; {
/* Failed, switch the way to terminate process with TerminateProcess. */
CloseHandle(jo);
jo = NULL;
}
winpty_spawn_config_free(spawn_config); winpty_spawn_config_free(spawn_config);
vim_free(p);
create_vterm(term, rows, cols); create_vterm(term, rows, cols);
@ -1246,6 +1252,9 @@ term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
return OK; return OK;
failed: failed:
if (spawn_config != NULL)
winpty_spawn_config_free(spawn_config);
vim_free(p);
if (channel != NULL) if (channel != NULL)
channel_clear(channel); channel_clear(channel);
if (job != NULL) if (job != NULL)

View File

@ -769,6 +769,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 */
/**/
781,
/**/ /**/
780, 780,
/**/ /**/