Skip to content

Commit b8d4905

Browse files
committed
patch 7.4.1814
Problem: A channel may be garbage collected while it's still being used by a job. (James McCoy) Solution: Mark the channel as used if the job is still used. Do the same for channels that are still used.
1 parent 9b4ebc6 commit b8d4905

4 files changed

Lines changed: 29 additions & 18 deletions

File tree

src/channel.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,28 +3553,15 @@ set_ref_in_channel(int copyID)
35533553
{
35543554
int abort = FALSE;
35553555
channel_T *channel;
3556-
int part;
3556+
typval_T tv;
35573557

35583558
for (channel = first_channel; channel != NULL; channel = channel->ch_next)
3559-
{
3560-
for (part = PART_SOCK; part < PART_IN; ++part)
3559+
if (channel_still_useful(channel))
35613560
{
3562-
jsonq_T *head = &channel->ch_part[part].ch_json_head;
3563-
jsonq_T *item = head->jq_next;
3564-
3565-
while (item != NULL)
3566-
{
3567-
list_T *l = item->jq_value->vval.v_list;
3568-
3569-
if (l->lv_copyID != copyID)
3570-
{
3571-
l->lv_copyID = copyID;
3572-
abort = abort || set_ref_in_list(l, copyID, NULL);
3573-
}
3574-
item = item->jq_next;
3575-
}
3561+
tv.v_type = VAR_CHANNEL;
3562+
tv.vval.v_channel = channel;
3563+
abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
35763564
}
3577-
}
35783565
return abort;
35793566
}
35803567

@@ -4092,6 +4079,26 @@ job_still_useful(job_T *job)
40924079
&& channel_still_useful(job->jv_channel)));
40934080
}
40944081

4082+
/*
4083+
* Mark references in jobs that are still useful.
4084+
*/
4085+
int
4086+
set_ref_in_job(int copyID)
4087+
{
4088+
int abort = FALSE;
4089+
job_T *job;
4090+
typval_T tv;
4091+
4092+
for (job = first_job; job != NULL; job = job->jv_next)
4093+
if (job_still_useful(job))
4094+
{
4095+
tv.v_type = VAR_JOB;
4096+
tv.vval.v_job = job;
4097+
abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
4098+
}
4099+
return abort;
4100+
}
4101+
40954102
void
40964103
job_unref(job_T *job)
40974104
{

src/eval.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7024,6 +7024,7 @@ garbage_collect(int testing)
70247024

70257025
#ifdef FEAT_JOB_CHANNEL
70267026
abort = abort || set_ref_in_channel(copyID);
7027+
abort = abort || set_ref_in_job(copyID);
70277028
#endif
70287029
#ifdef FEAT_NETBEANS_INTG
70297030
abort = abort || set_ref_in_nb_channel(copyID);

src/proto/channel.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void clear_job_options(jobopt_T *opt);
4949
void free_job_options(jobopt_T *opt);
5050
int get_job_options(typval_T *tv, jobopt_T *opt, int supported);
5151
channel_T *get_channel_arg(typval_T *tv, int check_open, int reading, int part);
52+
int set_ref_in_job(int copyID);
5253
void job_unref(job_T *job);
5354
int free_unused_jobs_contents(int copyID, int mask);
5455
void free_unused_jobs(int copyID, int mask);

src/version.c

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

754754
static int included_patches[] =
755755
{ /* Add new patch number below this line */
756+
/**/
757+
1814,
756758
/**/
757759
1813,
758760
/**/

0 commit comments

Comments
 (0)