patch 8.1.2018: using freed memory when out of memory and displaying message
Problem: Using freed memory when out of memory and displaying message.
Solution: Make a copy of the message first.
diff --git a/src/normal.c b/src/normal.c
index 7abd3fc..d169f26 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -1182,12 +1182,17 @@
kmsg = keep_msg;
keep_msg = NULL;
- /* showmode() will clear keep_msg, but we want to use it anyway */
+ // showmode() will clear keep_msg, but we want to use it anyway
update_screen(0);
- /* now reset it, otherwise it's put in the history again */
+ // now reset it, otherwise it's put in the history again
keep_msg = kmsg;
- msg_attr((char *)kmsg, keep_msg_attr);
- vim_free(kmsg);
+
+ kmsg = vim_strsave(keep_msg);
+ if (kmsg != NULL)
+ {
+ msg_attr((char *)kmsg, keep_msg_attr);
+ vim_free(kmsg);
+ }
}
setcursor();
cursor_on();