@@ -1084,13 +1084,19 @@ term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
10841084 if (channel != NULL )
10851085 channel_clear (channel );
10861086 if (job != NULL )
1087+ {
1088+ job -> jv_channel = NULL ;
10871089 job_cleanup (job );
1090+ }
1091+ term -> tl_job = NULL ;
10881092 if (jo != NULL )
10891093 CloseHandle (jo );
10901094 if (term -> tl_winpty != NULL )
10911095 winpty_free (term -> tl_winpty );
1096+ term -> tl_winpty = NULL ;
10921097 if (term -> tl_winpty_config != NULL )
10931098 winpty_config_free (term -> tl_winpty_config );
1099+ term -> tl_winpty_config = NULL ;
10941100 if (winpty_err != NULL )
10951101 {
10961102 char_u * msg = utf16_to_enc (
@@ -1108,9 +1114,12 @@ term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
11081114 static void
11091115term_free (term_T * term )
11101116{
1111- winpty_free (term -> tl_winpty );
1112- winpty_config_free (term -> tl_winpty_config );
1113- vterm_free (term -> tl_vterm );
1117+ if (term -> tl_winpty != NULL )
1118+ winpty_free (term -> tl_winpty );
1119+ if (term -> tl_winpty_config != NULL )
1120+ winpty_config_free (term -> tl_winpty_config );
1121+ if (term -> tl_vterm != NULL )
1122+ vterm_free (term -> tl_vterm );
11141123}
11151124
11161125# else
@@ -1149,7 +1158,8 @@ term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
11491158 static void
11501159term_free (term_T * term )
11511160{
1152- vterm_free (term -> tl_vterm );
1161+ if (term -> tl_vterm != NULL )
1162+ vterm_free (term -> tl_vterm );
11531163}
11541164# endif
11551165
0 commit comments