summaryrefslogtreecommitdiff
path: root/src/channel.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-02-16 13:33:52 +0100
committerBram Moolenaar <Bram@vim.org>2016-02-16 13:33:52 +0100
commitd46ae142aa9452e99576b5e923de974704e3c896 (patch)
tree5c70cdc03112703b69ca21e390219d9337a29bd5 /src/channel.c
parent0943a09db84b036ec550d7f2e5b832f621b400ca (diff)
downloadvim-git-d46ae142aa9452e99576b5e923de974704e3c896.tar.gz
patch 7.4.1331v7.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.
Diffstat (limited to 'src/channel.c')
-rw-r--r--src/channel.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/channel.c b/src/channel.c
index 10d942425..28fee0ac9 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -888,8 +888,7 @@ channel_parse_json(channel_T *channel)
}
/*
- * Remove "node" from the queue that it is in and free it.
- * Also frees the contained callback name.
+ * 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,8 +901,6 @@ remove_cb_node(cbq_T *head, cbq_T *node)
head->cq_prev = node->cq_prev;
else
node->cq_next->cq_prev = node->cq_prev;
- vim_free(node->cq_callback);
- vim_free(node);
}
/*
@@ -1144,8 +1141,12 @@ may_invoke_callback(channel_T *channel)
if (item->cq_seq_nr == seq_nr)
{
ch_log(channel, "Invoking one-time callback\n");
- invoke_callback(channel, item->cq_callback, argv);
+ /* 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,7 +1330,13 @@ channel_clear(channel_T *channel)
vim_free(channel_get(channel));
while (cb_head->cq_next != NULL)
- remove_cb_node(cb_head, cb_head->cq_next);
+ {
+ 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)
{