@@ -461,8 +461,7 @@ free_unused_channels(int copyID, int mask)
461461 ch_next = ch -> ch_next ;
462462 if ((ch -> ch_copyID & mask ) != (copyID & mask ))
463463 {
464- /* Free the channel and ordinary items it contains, but don't
465- * recurse into Lists, Dictionaries etc. */
464+ /* Free the channel struct itself. */
466465 channel_free_channel (ch );
467466 }
468467 }
@@ -4025,15 +4024,25 @@ job_free(job_T *job)
40254024 }
40264025}
40274026
4027+ /*
4028+ * Return TRUE if the job should not be freed yet. Do not free the job when
4029+ * it has not ended yet and there is a "stoponexit" flag or an exit callback.
4030+ */
4031+ static int
4032+ job_still_useful (job_T * job )
4033+ {
4034+ return job -> jv_status == JOB_STARTED
4035+ && (job -> jv_stoponexit != NULL || job -> jv_exit_cb != NULL );
4036+ }
4037+
40284038 void
40294039job_unref (job_T * job )
40304040{
40314041 if (job != NULL && -- job -> jv_refcount <= 0 )
40324042 {
40334043 /* Do not free the job when it has not ended yet and there is a
40344044 * "stoponexit" flag or an exit callback. */
4035- if (job -> jv_status != JOB_STARTED
4036- || (job -> jv_stoponexit == NULL && job -> jv_exit_cb == NULL ))
4045+ if (!job_still_useful (job ))
40374046 {
40384047 job_free (job );
40394048 }
@@ -4055,7 +4064,8 @@ free_unused_jobs_contents(int copyID, int mask)
40554064 job_T * job ;
40564065
40574066 for (job = first_job ; job != NULL ; job = job -> jv_next )
4058- if ((job -> jv_copyID & mask ) != (copyID & mask ))
4067+ if ((job -> jv_copyID & mask ) != (copyID & mask )
4068+ && !job_still_useful (job ))
40594069 {
40604070 /* Free the channel and ordinary items it contains, but don't
40614071 * recurse into Lists, Dictionaries etc. */
@@ -4074,10 +4084,10 @@ free_unused_jobs(int copyID, int mask)
40744084 for (job = first_job ; job != NULL ; job = job_next )
40754085 {
40764086 job_next = job -> jv_next ;
4077- if ((job -> jv_copyID & mask ) != (copyID & mask ))
4087+ if ((job -> jv_copyID & mask ) != (copyID & mask )
4088+ && !job_still_useful (job ))
40784089 {
4079- /* Free the channel and ordinary items it contains, but don't
4080- * recurse into Lists, Dictionaries etc. */
4090+ /* Free the job struct itself. */
40814091 job_free_job (job );
40824092 }
40834093 }
0 commit comments