@@ -307,11 +307,14 @@ add_channel(void)
307307}
308308
309309/*
310- * Return TRUE if "channel" has a callback.
310+ * Return TRUE if "channel" has a callback and the associated job wasn't
311+ * killed.
311312 */
312313 static int
313- channel_has_callback (channel_T * channel )
314+ channel_still_useful (channel_T * channel )
314315{
316+ if (channel -> ch_job_killed && channel -> ch_job == NULL )
317+ return FALSE;
315318 return channel -> ch_callback != NULL
316319#ifdef CHANNEL_PIPES
317320 || channel -> ch_part [PART_OUT ].ch_callback != NULL
@@ -322,12 +325,13 @@ channel_has_callback(channel_T *channel)
322325
323326/*
324327 * Close a channel and free all its resources if there is no further action
325- * possible, there is no callback to be invoked.
328+ * possible, there is no callback to be invoked or the associated job was
329+ * killed.
326330 */
327331 void
328332channel_may_free (channel_T * channel )
329333{
330- if (!channel_has_callback (channel ))
334+ if (!channel_still_useful (channel ))
331335 channel_free (channel );
332336}
333337
@@ -1774,6 +1778,12 @@ channel_read(channel_T *channel, int part, char *func)
17741778 * -> channel_read()
17751779 */
17761780 ch_errors (channel , "%s(): Cannot read" , func );
1781+ if (len < 0 )
1782+ {
1783+ ch_error (channel , "channel_read(): cannot read from channel" );
1784+ PERROR (_ ("E896: read from channel" ));
1785+ }
1786+
17771787 msg = channel -> ch_part [part ].ch_mode == MODE_RAW
17781788 || channel -> ch_part [part ].ch_mode == MODE_NL
17791789 ? DETACH_MSG_RAW : DETACH_MSG_JSON ;
@@ -1785,12 +1795,6 @@ channel_read(channel_T *channel, int part, char *func)
17851795 channel_close (channel , TRUE);
17861796 if (channel -> ch_nb_close_cb != NULL )
17871797 (* channel -> ch_nb_close_cb )();
1788-
1789- if (len < 0 )
1790- {
1791- ch_error (channel , "channel_read(): cannot read from channel" );
1792- PERROR (_ ("E896: read from channel" ));
1793- }
17941798 }
17951799
17961800#if defined(CH_HAS_GUI ) && defined(FEAT_GUI_GTK )
@@ -2174,7 +2178,7 @@ channel_parse_messages(void)
21742178
21752179 while (channel != NULL )
21762180 {
2177- if (channel -> ch_refcount == 0 && !channel_has_callback (channel ))
2181+ if (channel -> ch_refcount == 0 && !channel_still_useful (channel ))
21782182 {
21792183 /* channel is no longer useful, free it */
21802184 channel_free (channel );
0 commit comments