Skip to content

Commit ab6eec3

Browse files
committed
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)
1 parent cb25d18 commit ab6eec3

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/terminal.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,18 +1153,19 @@ dyn_winpty_init(void)
11531153
static int
11541154
term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
11551155
{
1156-
WCHAR *p = enc_to_utf16(cmd, NULL);
1156+
WCHAR *p;
11571157
channel_T *channel = NULL;
11581158
job_T *job = NULL;
11591159
jobopt_T opt;
11601160
DWORD error;
11611161
HANDLE jo = NULL, child_process_handle, child_thread_handle;
11621162
void *winpty_err;
1163-
void *spawn_config;
1163+
void *spawn_config = NULL;
11641164

11651165
if (!dyn_winpty_init())
11661166
return FAIL;
11671167

1168+
p = enc_to_utf16(cmd, NULL);
11681169
if (p == NULL)
11691170
return FAIL;
11701171

@@ -1227,9 +1228,14 @@ term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
12271228
goto failed;
12281229

12291230
if (!AssignProcessToJobObject(jo, child_process_handle))
1230-
goto failed;
1231+
{
1232+
/* Failed, switch the way to terminate process with TerminateProcess. */
1233+
CloseHandle(jo);
1234+
jo = NULL;
1235+
}
12311236

12321237
winpty_spawn_config_free(spawn_config);
1238+
vim_free(p);
12331239

12341240
create_vterm(term, rows, cols);
12351241

@@ -1246,6 +1252,9 @@ term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
12461252
return OK;
12471253

12481254
failed:
1255+
if (spawn_config != NULL)
1256+
winpty_spawn_config_free(spawn_config);
1257+
vim_free(p);
12491258
if (channel != NULL)
12501259
channel_clear(channel);
12511260
if (job != NULL)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
781,
772774
/**/
773775
780,
774776
/**/

0 commit comments

Comments
 (0)