To: vim_dev@googlegroups.com Subject: Patch 7.4.1855 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1855 Problem: Valgrind reports memory leak for job that is not freed. Solution: Free all jobs on exit. Add test for failing job. Files: src/channel.c, src/misc2.c, src/proto/channel.pro, src/testdir/test_partial.vim *** ../vim-7.4.1854/src/channel.c 2016-05-28 14:16:05.290615005 +0200 --- src/channel.c 2016-05-28 21:10:42.582272798 +0200 *************** *** 1285,1290 **** --- 1285,1291 ---- int len = (int)STRLEN(line); char_u *p; + /* Need to make a copy to be able to append a NL. */ if ((p = alloc(len + 2)) == NULL) return; STRCPY(p, line); *************** *** 2888,2894 **** /* * Read from channel "channel" for as long as there is something to read. * "part" is PART_SOCK, PART_OUT or PART_ERR. ! * The data is put in the read queue. */ static void channel_read(channel_T *channel, int part, char *func) --- 2889,2895 ---- /* * Read from channel "channel" for as long as there is something to read. * "part" is PART_SOCK, PART_OUT or PART_ERR. ! * The data is put in the read queue. No callbacks are invoked here. */ static void channel_read(channel_T *channel, int part, char *func) *************** *** 4184,4189 **** --- 4185,4199 ---- } } + #if defined(EXITFREE) || defined(PROTO) + void + job_free_all(void) + { + while (first_job != NULL) + job_free(first_job); + } + #endif + /* * Return TRUE if the job should not be freed yet. Do not free the job when * it has not ended yet and there is a "stoponexit" flag, an exit callback *** ../vim-7.4.1854/src/misc2.c 2016-03-28 19:16:15.665846533 +0200 --- src/misc2.c 2016-05-28 21:54:49.954236381 +0200 *************** *** 1127,1135 **** # ifdef FEAT_DIFF diff_clear(curtab); # endif - # ifdef FEAT_JOB_CHANNEL - channel_free_all(); - # endif clear_sb_text(); /* free any scrollback text */ /* Free some global vars. */ --- 1127,1132 ---- *************** *** 1221,1226 **** --- 1218,1227 ---- # ifdef FEAT_EVAL eval_clear(); # endif + # ifdef FEAT_JOB_CHANNEL + channel_free_all(); + job_free_all(); + # endif free_termoptions(); *** ../vim-7.4.1854/src/proto/channel.pro 2016-05-09 20:38:48.580112142 +0200 --- src/proto/channel.pro 2016-05-28 21:56:12.034235252 +0200 *************** *** 50,55 **** --- 50,56 ---- void free_job_options(jobopt_T *opt); int get_job_options(typval_T *tv, jobopt_T *opt, int supported); channel_T *get_channel_arg(typval_T *tv, int check_open, int reading, int part); + void job_free_all(void); int set_ref_in_job(int copyID); void job_unref(job_T *job); int free_unused_jobs_contents(int copyID, int mask); *** ../vim-7.4.1854/src/testdir/test_partial.vim 2016-05-24 22:29:45.038961566 +0200 --- src/testdir/test_partial.vim 2016-05-28 22:17:17.030217851 +0200 *************** *** 250,255 **** --- 250,269 ---- endif endfunc + func Test_job_start_fails() + if has('job') + let job = job_start('axdfxsdf') + for i in range(100) + if job_status(job) == 'dead' + break + endif + sleep 10m + endfor + call assert_equal('dead', job_status(job)) + unlet job + endif + endfunc + func Test_ref_job_partial_dict() if has('job') let g:ref_job = job_start('echo') *** ../vim-7.4.1854/src/version.c 2016-05-28 15:53:45.874534388 +0200 --- src/version.c 2016-05-28 22:17:58.406217282 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 1855, /**/ -- How To Keep A Healthy Level Of Insanity: 2. Page yourself over the intercom. Don't disguise your voice. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///