patch 7.4.1386 v7.4.1386
authorBram Moolenaar <Bram@vim.org>
Mon, 22 Feb 2016 10:39:27 +0000 (11:39 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 22 Feb 2016 10:39:27 +0000 (11:39 +0100)
Problem:    When the Job exit callback is invoked, the job may be freed too
            soon. (Yasuhiro Matsumoto)
Solution:   Increase refcount.

src/eval.c
src/version.c

index 3fb06d00ea564c16113c39dfbe195b7ec3d6e528..cc3030849537e0102ae45d7f946fa64014761971 100644 (file)
@@ -15039,7 +15039,8 @@ job_status(job_T *job)
            typval_T    rettv;
            int         dummy;
 
-           /* invoke the exit callback */
+           /* invoke the exit callback; make sure the refcount is > 0 */
+           ++job->jv_refcount;
            argv[0].v_type = VAR_JOB;
            argv[0].vval.v_job = job;
            argv[1].v_type = VAR_NUMBER;
@@ -15047,10 +15048,11 @@ job_status(job_T *job)
            call_func(job->jv_exit_cb, (int)STRLEN(job->jv_exit_cb),
                                 &rettv, 2, argv, 0L, 0L, &dummy, TRUE, NULL);
            clear_tv(&rettv);
+           --job->jv_refcount;
        }
        if (job->jv_status == JOB_ENDED && job->jv_refcount == 0)
        {
-           /* The job already was unreferenced, now that it ended it can be
+           /* The job was already unreferenced, now that it ended it can be
             * freed. Careful: caller must not use "job" after this! */
            job_free(job);
        }
index 9e2f4bd81bbb403702db8102909e10e85f255a79..778d1fc4add38a643f8ac913286570765c329ca5 100644 (file)
@@ -748,6 +748,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1386,
 /**/
     1385,
 /**/