]> granicus.if.org Git - vim/commitdiff
patch 8.1.0400: using freed memory with :diffget v8.1.0400
authorBram Moolenaar <Bram@vim.org>
Sun, 16 Sep 2018 16:10:48 +0000 (18:10 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 16 Sep 2018 16:10:48 +0000 (18:10 +0200)
Problem:    Using freed memory with :diffget.
Solution:   Skip ex_diffupdate() while updating diffs. (closes #3442)

src/diff.c
src/version.c

index 809694a68c21e7fce022a7ab6f9ed8f54668a120..d523e7743a9e584eb4470465752c139b1fe3fb4a 100644 (file)
@@ -21,7 +21,8 @@
 
 #if defined(FEAT_DIFF) || defined(PROTO)
 
-static int     diff_busy = FALSE;      /* ex_diffgetput() is busy */
+static int diff_busy = FALSE;      // using diff structs, don't change them
+static int diff_need_update = FALSE; // ex_diffupdate needs to be called
 
 /* flags obtained from the 'diffopt' option */
 #define DIFF_FILLER    0x001   // display filler lines
@@ -908,6 +909,12 @@ ex_diffupdate(exarg_T *eap)        // "eap" can be NULL
     int                idx_new;
     diffio_T   diffio;
 
+    if (diff_busy)
+    {
+       diff_need_update = TRUE;
+       return;
+    }
+
     // Delete all diffblocks.
     diff_clear(curtab);
     curtab->tp_diff_invalid = FALSE;
@@ -2660,7 +2667,7 @@ ex_diffgetput(exarg_T *eap)
        if (diff_buf_idx(curbuf) != idx_to)
        {
            EMSG(_("E787: Buffer changed unexpectedly"));
-           return;
+           goto theend;
        }
     }
 
@@ -2831,7 +2838,13 @@ ex_diffgetput(exarg_T *eap)
        aucmd_restbuf(&aco);
     }
 
+theend:
     diff_busy = FALSE;
+    if (diff_need_update)
+    {
+       diff_need_update = FALSE;
+       ex_diffupdate(NULL);
+    }
 
     /* Check that the cursor is on a valid character and update it's position.
      * When there were filler lines the topline has become invalid. */
index f991cd0d41b79bd9fc737b548f25b28d202ccf1a..d3cc1951f8952f81de16ab4f6b99ac77c61734f8 100644 (file)
@@ -794,6 +794,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    400,
 /**/
     399,
 /**/