summaryrefslogtreecommitdiffstats
path: root/src/autocmd.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-11-13 17:53:46 +0000
committerBram Moolenaar <Bram@vim.org>2022-11-13 17:53:46 +0000
commit3b014befa006b7224a84d7d58d9603fc261f34cd (patch)
treee3fd53778f0a9a46bb46e6d096ece9e0f51ac18f /src/autocmd.c
parent2f7bfe66a1373051792f2ecaeefb66049825221d (diff)
patch 9.0.0871: using freed memory when clearing augroup at more promptv9.0.0871
Problem: Using freed memory when clearing augroup at more prompt. Solution: Delay clearing augroup until it's safe. (closes #11441)
Diffstat (limited to 'src/autocmd.c')
-rw-r--r--src/autocmd.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/autocmd.c b/src/autocmd.c
index cf0f0946a8..8a0992c092 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -296,9 +296,14 @@ show_autocmd(AutoPat *ap, event_T event)
if (ap->pat == NULL) // pattern has been removed
return;
+ // Make sure no info referenced by "ap" is cleared, e.g. when a timer
+ // clears an augroup. Jump to "theend" after this!
+ // "ap->pat" may be cleared anyway.
+ ++autocmd_busy;
+
msg_putchar('\n');
if (got_int)
- return;
+ goto theend;
if (event != last_event || ap->group != last_group)
{
if (ap->group != AUGROUP_DEFAULT)
@@ -314,8 +319,12 @@ show_autocmd(AutoPat *ap, event_T event)
last_group = ap->group;
msg_putchar('\n');
if (got_int)
- return;
+ goto theend;
}
+
+ if (ap->pat == NULL)
+ goto theend; // timer might have cleared the pattern or group
+
msg_col = 4;
msg_outtrans(ap->pat);
@@ -328,21 +337,24 @@ show_autocmd(AutoPat *ap, event_T event)
msg_putchar('\n');
msg_col = 14;
if (got_int)
- return;
+ goto theend;
msg_outtrans(ac->cmd);
#ifdef FEAT_EVAL
if (p_verbose > 0)
last_set_msg(ac->script_ctx);
#endif
if (got_int)
- return;
+ goto theend;
if (ac->next != NULL)
{
msg_putchar('\n');
if (got_int)
- return;
+ goto theend;
}
}
+
+theend:
+ --autocmd_busy;
}
/*