comparison src/channel.c @ 12403:b44bd42a374e v8.0.1081

patch 8.0.1081: memory leak for the channel write queue commit https://github.com/vim/vim/commit/aba680a8513124e9556956115db4df35bd4a0e56 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 9 16:42:53 2017 +0200 patch 8.0.1081: memory leak for the channel write queue Problem: Memory leak for the channel write queue. Solution: Free the write queue when clearing a channel.
author Christian Brabandt <cb@256bit.org>
date Sat, 09 Sep 2017 16:45:05 +0200
parents 128cd982c7b8
children e9dbdc4d8279
comparison
equal deleted inserted replaced
12402:67ab87d334e9 12403:b44bd42a374e
2928 channel_close_in(channel_T *channel) 2928 channel_close_in(channel_T *channel)
2929 { 2929 {
2930 ch_close_part(channel, PART_IN); 2930 ch_close_part(channel, PART_IN);
2931 } 2931 }
2932 2932
2933 static void
2934 remove_from_writeque(writeq_T *wq, writeq_T *entry)
2935 {
2936 ga_clear(&entry->wq_ga);
2937 wq->wq_next = entry->wq_next;
2938 if (wq->wq_next == NULL)
2939 wq->wq_prev = NULL;
2940 else
2941 wq->wq_next->wq_prev = NULL;
2942 }
2943
2933 /* 2944 /*
2934 * Clear the read buffer on "channel"/"part". 2945 * Clear the read buffer on "channel"/"part".
2935 */ 2946 */
2936 static void 2947 static void
2937 channel_clear_one(channel_T *channel, ch_part_T part) 2948 channel_clear_one(channel_T *channel, ch_part_T part)
2938 { 2949 {
2939 jsonq_T *json_head = &channel->ch_part[part].ch_json_head; 2950 chanpart_T *ch_part = &channel->ch_part[part];
2940 cbq_T *cb_head = &channel->ch_part[part].ch_cb_head; 2951 jsonq_T *json_head = &ch_part->ch_json_head;
2952 cbq_T *cb_head = &ch_part->ch_cb_head;
2941 2953
2942 while (channel_peek(channel, part) != NULL) 2954 while (channel_peek(channel, part) != NULL)
2943 vim_free(channel_get(channel, part)); 2955 vim_free(channel_get(channel, part));
2944 2956
2945 while (cb_head->cq_next != NULL) 2957 while (cb_head->cq_next != NULL)
2955 { 2967 {
2956 free_tv(json_head->jq_next->jq_value); 2968 free_tv(json_head->jq_next->jq_value);
2957 remove_json_node(json_head, json_head->jq_next); 2969 remove_json_node(json_head, json_head->jq_next);
2958 } 2970 }
2959 2971
2960 free_callback(channel->ch_part[part].ch_callback, 2972 free_callback(ch_part->ch_callback, ch_part->ch_partial);
2961 channel->ch_part[part].ch_partial); 2973 ch_part->ch_callback = NULL;
2962 channel->ch_part[part].ch_callback = NULL; 2974 ch_part->ch_partial = NULL;
2963 channel->ch_part[part].ch_partial = NULL; 2975
2976 while (ch_part->ch_writeque.wq_next != NULL)
2977 remove_from_writeque(&ch_part->ch_writeque,
2978 ch_part->ch_writeque.wq_next);
2964 } 2979 }
2965 2980
2966 /* 2981 /*
2967 * Clear all the read buffers on "channel". 2982 * Clear all the read buffers on "channel".
2968 */ 2983 */
3717 { 3732 {
3718 /* Wrote all the buf[len] bytes. */ 3733 /* Wrote all the buf[len] bytes. */
3719 if (entry != NULL) 3734 if (entry != NULL)
3720 { 3735 {
3721 /* Remove the entry from the write queue. */ 3736 /* Remove the entry from the write queue. */
3722 ga_clear(&entry->wq_ga); 3737 remove_from_writeque(wq, entry);
3723 wq->wq_next = entry->wq_next;
3724 if (wq->wq_next == NULL)
3725 wq->wq_prev = NULL;
3726 else
3727 wq->wq_next->wq_prev = NULL;
3728 continue; 3738 continue;
3729 } 3739 }
3730 if (did_use_queue) 3740 if (did_use_queue)
3731 ch_log(channel, "Write queue empty"); 3741 ch_log(channel, "Write queue empty");
3732 } 3742 }