diff src/quickfix.c @ 27855:44a552776007 v8.2.4453

patch 8.2.4453: :helpgrep may free an option that was not allocated Commit: https://github.com/vim/vim/commit/4791fcd82565adcc60b86830e0bb6cd5b6eea0a6 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 23 12:06:00 2022 +0000 patch 8.2.4453: :helpgrep may free an option that was not allocated Problem: :helpgrep may free an option that was not allocated. (Yegappan Lakshmanan) Solution: Check if the value was allocated.
author Bram Moolenaar <Bram@vim.org>
date Wed, 23 Feb 2022 13:15:02 +0100
parents c1d1639b52dd
children d1af65b322d0
line wrap: on
line diff
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -8235,6 +8235,7 @@ ex_helpgrep(exarg_T *eap)
 {
     regmatch_T	regmatch;
     char_u	*save_cpo;
+    int		save_cpo_allocated;
     qf_info_T	*qi = &ql_info;
     int		new_qi = FALSE;
     char_u	*au_name =  NULL;
@@ -8265,6 +8266,7 @@ ex_helpgrep(exarg_T *eap)
 
     // Make 'cpoptions' empty, the 'l' flag should not be used here.
     save_cpo = p_cpo;
+    save_cpo_allocated = is_option_allocated("cpo");
     p_cpo = empty_option;
 
     incr_quickfix_busy();
@@ -8302,7 +8304,8 @@ ex_helpgrep(exarg_T *eap)
 	// changed and restored, need to restore in the complicated way.
 	if (*p_cpo == NUL)
 	    set_option_value((char_u *)"cpo", 0L, save_cpo, 0);
-	free_string_option(save_cpo);
+	if (save_cpo_allocated)
+	    free_string_option(save_cpo);
     }
 
     if (updated)