]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 7.4.1261 v7.4.1261
authorBram Moolenaar <Bram@vim.org>
Thu, 4 Feb 2016 21:49:49 +0000 (22:49 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 4 Feb 2016 21:49:49 +0000 (22:49 +0100)
Problem:    Pending channel messages are garbage collected. Leaking memory in
            ch_sendexpr().  Leaking memory for a decoded JSON string.
Solution:   Mark the message list as used. Free the encoded JSON.  Don't save
            the JSON string.

src/channel.c
src/eval.c
src/json.c
src/proto/channel.pro
src/version.c

index 1290171949bb841f7e9b5006586d88f2528fdc74..0ae90a963897b85e175df91390a3dddd06c3ad93 100644 (file)
@@ -1315,4 +1315,29 @@ channel_parse_messages(void)
     return ret;
 }
 
+    int
+set_ref_in_channel(int copyID)
+{
+    int            i;
+    int            abort = FALSE;
+
+    for (i = 0; i < channel_count; ++i)
+    {
+       jsonq_T *head = &channels[i].ch_json_head;
+       jsonq_T *item = head->next;
+
+       while (item != head)
+       {
+           list_T      *l = item->value->vval.v_list;
+
+           if (l->lv_copyID != copyID)
+           {
+               l->lv_copyID = copyID;
+               abort = abort || set_ref_in_list(l, copyID, NULL);
+           }
+           item = item->next;
+       }
+    }
+    return abort;
+}
 #endif /* FEAT_CHANNEL */
index 892e14adac6ab4801e1a957d83b909e70fe4b80b..f13486f227fe2ad984ae81a91795104ece91958b 100644 (file)
@@ -6855,6 +6855,10 @@ garbage_collect(void)
     abort = abort || set_ref_in_python3(copyID);
 #endif
 
+#ifdef FEAT_CHANNEL
+    abort = abort || set_ref_in_channel(copyID);
+#endif
+
     if (!abort)
     {
        /*
@@ -9842,6 +9846,7 @@ f_ch_sendexpr(typval_T *argvars, typval_T *rettv)
        return;
 
     ch_idx = send_common(argvars, text, "sendexpr");
+    vim_free(text);
     if (ch_idx >= 0)
     {
        if (channel_read_json_block(ch_idx, id, &listtv) == OK)
index f97d2831203e2b611a0578cf8c7df47748157c49..b6fce02dc7848a060ff3a2d20a91ca3ff5c3bfae 100644 (file)
@@ -533,10 +533,7 @@ json_decode_string(js_read_T *reader, typval_T *res)
        if (res != NULL)
        {
            res->v_type = VAR_STRING;
-           if (ga.ga_data == NULL)
-               res->vval.v_string = NULL;
-           else
-               res->vval.v_string = vim_strsave(ga.ga_data);
+           res->vval.v_string = ga.ga_data;
        }
        return OK;
     }
index f53ac6680eca2cd70285a82261a4cf0df62b8ba3..197cddf8680aa9d334fe09cb90ffab4a68ae1f6e 100644 (file)
@@ -22,4 +22,5 @@ int channel_poll_check(int ret_in, void *fds_in);
 int channel_select_setup(int maxfd_in, void *rfds_in);
 int channel_select_check(int ret_in, void *rfds_in);
 int channel_parse_messages(void);
+int set_ref_in_channel(int copyID);
 /* vim: set ft=c : */
index 8611d49c18f5de1e09fe772677bb6a8514dc797b..1fbc721afa88a932d3dec2b0156a59130934afea 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1261,
 /**/
     1260,
 /**/