To: vim_dev@googlegroups.com Subject: Patch 8.0.1552 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1552 Problem: May leak file descriptors when executing job. Solution: Close more file descriptors. (Ozaki Kiichi, closes #2531) Files: src/os_unix.c, src/testdir/test_channel.vim *** ../vim-8.0.1551/src/os_unix.c 2018-02-27 17:58:16.672104019 +0100 --- src/os_unix.c 2018-02-27 18:59:30.187978389 +0100 *************** *** 4601,4606 **** --- 4601,4612 ---- reset_signals(); /* handle signals normally */ UNBLOCK_SIGNALS(&curset); + # ifdef FEAT_JOB_CHANNEL + if (ch_log_active()) + /* close the log file in the child */ + ch_logfile((char_u *)"", (char_u *)""); + # endif + if (!show_shell_mess || (options & SHELL_EXPAND)) { int fd; *************** *** 5454,5459 **** --- 5460,5471 ---- reset_signals(); /* handle signals normally */ UNBLOCK_SIGNALS(&curset); + # ifdef FEAT_JOB_CHANNEL + if (ch_log_active()) + /* close the log file in the child */ + ch_logfile((char_u *)"", (char_u *)""); + # endif + # ifdef HAVE_SETSID /* Create our own process group, so that the child and all its * children can be kill()ed. Don't do this when using pipes, *************** *** 5587,5597 **** if (pty_master_fd >= 0) close(pty_slave_fd); /* not used in the parent */ /* close child stdin, stdout and stderr */ ! if (!use_file_for_in && fd_in[0] >= 0) close(fd_in[0]); ! if (!use_file_for_out && fd_out[1] >= 0) close(fd_out[1]); ! if (!use_out_for_err && !use_file_for_err && fd_err[1] >= 0) close(fd_err[1]); if (channel != NULL) { --- 5599,5609 ---- if (pty_master_fd >= 0) close(pty_slave_fd); /* not used in the parent */ /* close child stdin, stdout and stderr */ ! if (fd_in[0] >= 0) close(fd_in[0]); ! if (fd_out[1] >= 0) close(fd_out[1]); ! if (fd_err[1] >= 0) close(fd_err[1]); if (channel != NULL) { *** ../vim-8.0.1551/src/testdir/test_channel.vim 2017-12-09 19:13:08.579678220 +0100 --- src/testdir/test_channel.vim 2018-02-27 19:02:23.450868502 +0100 *************** *** 23,28 **** --- 23,43 ---- call RunServer('test_channel.py', a:testfunc, a:000) endfunc + " Return a list of open files. + " Can be used to make sure no resources leaked. + " Returns an empty list on systems where this is not supported. + func s:get_resources() + let pid = getpid() + + if has('mac') + return systemlist('lsof -p ' . pid . ' | awk ''$4~/^[0-9]*[rwu]$/&&$5=="REG"{print$NF}''') + elseif isdirectory('/proc/' . pid . '/fd/') + return systemlist('readlink /proc/' . pid . '/fd/* | grep -v ''^/dev/''') + else + return [] + endif + endfunc + let g:Ch_responseMsg = '' func Ch_requestHandler(handle, msg) let g:Ch_responseHandle = a:handle *************** *** 620,625 **** --- 635,641 ---- call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput')) finally call Stop_g_job() + call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xoutput$')) call delete('Xoutput') endtry endfunc *************** *** 663,668 **** --- 679,685 ---- call assert_equal(['line one', 'line two', 'this', 'AND this', 'that', 'AND that'], readfile('Xoutput')) finally call Stop_g_job() + call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xoutput$')) call delete('Xoutput') endtry endfunc *************** *** 1662,1667 **** --- 1679,1685 ---- call assert_equal("asdf\nasdf", getline(1)) call assert_equal("xxx\n", getline(2)) call assert_equal("\nyyy", getline(3)) + call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xtestwrite$')) call delete('Xtestwrite') bwipe! *** ../vim-8.0.1551/src/version.c 2018-02-27 17:58:16.676103992 +0100 --- src/version.c 2018-02-27 18:56:06.141286468 +0100 *************** *** 780,781 **** --- 780,783 ---- { /* Add new patch number below this line */ + /**/ + 1552, /**/ -- ERIC IDLE PLAYED: THE DEAD COLLECTOR, MR BINT (A VILLAGE NE'ER-DO -WELL VERY KEEN ON BURNING WITCHES), SIR ROBIN, THE GUARD WHO DOESN'T HICOUGH BUT TRIES TO GET THINGS STRAIGHT, CONCORDE (SIR LAUNCELOT'S TRUSTY STEED), ROGER THE SHRUBBER (A SHRUBBER), BROTHER MAYNARD "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// 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 ///