Skip to content

Commit d2b58c0

Browse files
committed
patch 8.1.0400: using freed memory with :diffget
Problem: Using freed memory with :diffget. Solution: Skip ex_diffupdate() while updating diffs. (closes #3442)
1 parent 65985ac commit d2b58c0

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/diff.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
#if defined(FEAT_DIFF) || defined(PROTO)
2323

24-
static int diff_busy = FALSE; /* ex_diffgetput() is busy */
24+
static int diff_busy = FALSE; // using diff structs, don't change them
25+
static int diff_need_update = FALSE; // ex_diffupdate needs to be called
2526

2627
/* flags obtained from the 'diffopt' option */
2728
#define DIFF_FILLER 0x001 // display filler lines
@@ -908,6 +909,12 @@ ex_diffupdate(exarg_T *eap) // "eap" can be NULL
908909
int idx_new;
909910
diffio_T diffio;
910911

912+
if (diff_busy)
913+
{
914+
diff_need_update = TRUE;
915+
return;
916+
}
917+
911918
// Delete all diffblocks.
912919
diff_clear(curtab);
913920
curtab->tp_diff_invalid = FALSE;
@@ -2660,7 +2667,7 @@ ex_diffgetput(exarg_T *eap)
26602667
if (diff_buf_idx(curbuf) != idx_to)
26612668
{
26622669
EMSG(_("E787: Buffer changed unexpectedly"));
2663-
return;
2670+
goto theend;
26642671
}
26652672
}
26662673

@@ -2831,7 +2838,13 @@ ex_diffgetput(exarg_T *eap)
28312838
aucmd_restbuf(&aco);
28322839
}
28332840

2841+
theend:
28342842
diff_busy = FALSE;
2843+
if (diff_need_update)
2844+
{
2845+
diff_need_update = FALSE;
2846+
ex_diffupdate(NULL);
2847+
}
28352848

28362849
/* Check that the cursor is on a valid character and update it's position.
28372850
* When there were filler lines the topline has become invalid. */

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ static char *(features[]) =
794794

795795
static int included_patches[] =
796796
{ /* Add new patch number below this line */
797+
/**/
798+
400,
797799
/**/
798800
399,
799801
/**/

0 commit comments

Comments
 (0)