To: vim_dev@googlegroups.com Subject: Patch 7.4.1331 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1331 Problem: Crash when closing the channel in a callback. (Christian J. Robinson) Solution: Take the callback out of the list before invoking it. Files: src/channel.c, src/testdir/test_channel.vim *** ../vim-7.4.1330/src/channel.c 2016-02-16 13:11:13.525534005 +0100 --- src/channel.c 2016-02-16 13:28:44.514633684 +0100 *************** *** 888,895 **** } /* ! * Remove "node" from the queue that it is in and free it. ! * Also frees the contained callback name. */ static void remove_cb_node(cbq_T *head, cbq_T *node) --- 888,894 ---- } /* ! * Remove "node" from the queue that it is in. Does not free it. */ static void remove_cb_node(cbq_T *head, cbq_T *node) *************** *** 902,909 **** head->cq_prev = node->cq_prev; else node->cq_next->cq_prev = node->cq_prev; - vim_free(node->cq_callback); - vim_free(node); } /* --- 901,906 ---- *************** *** 1144,1151 **** if (item->cq_seq_nr == seq_nr) { ch_log(channel, "Invoking one-time callback\n"); ! invoke_callback(channel, item->cq_callback, argv); remove_cb_node(head, item); done = TRUE; break; } --- 1141,1152 ---- if (item->cq_seq_nr == seq_nr) { ch_log(channel, "Invoking one-time callback\n"); ! /* Remove the item from the list first, if the callback ! * invokes ch_close() the list will be cleared. */ remove_cb_node(head, item); + invoke_callback(channel, item->cq_callback, argv); + vim_free(item->cq_callback); + vim_free(item); done = TRUE; break; } *************** *** 1329,1335 **** vim_free(channel_get(channel)); while (cb_head->cq_next != NULL) ! remove_cb_node(cb_head, cb_head->cq_next); while (json_head->jq_next != NULL) { --- 1330,1342 ---- vim_free(channel_get(channel)); while (cb_head->cq_next != NULL) ! { ! cbq_T *node = cb_head->cq_next; ! ! remove_cb_node(cb_head, node); ! vim_free(node->cq_callback); ! vim_free(node); ! } while (json_head->jq_next != NULL) { *** ../vim-7.4.1330/src/testdir/test_channel.vim 2016-02-16 12:44:22.002282499 +0100 --- src/testdir/test_channel.vim 2016-02-16 13:22:05.822756469 +0100 *************** *** 301,306 **** --- 301,308 ---- endtry endfunc + """""""""" + let s:unletResponse = '' func s:UnletHandler(handle, msg) let s:unletResponse = a:msg *************** *** 319,324 **** --- 321,348 ---- call s:run_server('s:unlet_handle') endfunc + """""""""" + + let s:unletResponse = '' + func s:CloseHandler(handle, msg) + let s:unletResponse = a:msg + call ch_close(s:channelfd) + endfunc + + " Test that "unlet handle" in a handler doesn't crash Vim. + func s:close_handle(port) + let s:channelfd = ch_open('localhost:' . a:port, s:chopt) + call ch_sendexpr(s:channelfd, "test", function('s:CloseHandler')) + sleep 10m + call assert_equal('what?', s:unletResponse) + endfunc + + func Test_close_handle() + call s:run_server('s:close_handle') + endfunc + + """""""""" + func Test_open_fail() silent! let ch = ch_open("noserver") echo ch *** ../vim-7.4.1330/src/version.c 2016-02-16 13:11:13.525534005 +0100 --- src/version.c 2016-02-16 13:32:30.408296733 +0100 *************** *** 749,750 **** --- 749,752 ---- { /* Add new patch number below this line */ + /**/ + 1331, /**/ -- GOD: That is your purpose Arthur ... the Quest for the Holy Grail ... "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 ///