diff src/cmdexpand.c @ 17801:6582dda76821 v8.1.1897

patch 8.1.1897: may free memory twice when out of memory commit https://github.com/vim/vim/commit/f1552d07d715b437d941659479942c2543b02bd4 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 21 12:54:18 2019 +0200 patch 8.1.1897: may free memory twice when out of memory Problem: May free memory twice when out of memory. Solution: Check that backslash_halve_save() returns a different pointer. (Dominique Pelle, closes #4847)
author Bram Moolenaar <Bram@vim.org>
date Wed, 21 Aug 2019 13:00:03 +0200
parents 04245f071792
children fd6c8dc33152
line wrap: on
line diff
--- a/src/cmdexpand.c
+++ b/src/cmdexpand.c
@@ -646,17 +646,19 @@ showmatches(expand_T *xp, int wildmenu U
 		    {
 			char_u	*halved_slash;
 			char_u	*exp_path;
+			char_u	*path;
 
 			// Expansion was done before and special characters
 			// were escaped, need to halve backslashes.  Also
 			// $HOME has been replaced with ~/.
 			exp_path = expand_env_save_opt(files_found[k], TRUE);
-			halved_slash = backslash_halve_save(
-				exp_path != NULL ? exp_path : files_found[k]);
+			path = exp_path != NULL ? exp_path : files_found[k];
+			halved_slash = backslash_halve_save(path);
 			j = mch_isdir(halved_slash != NULL ? halved_slash
 							    : files_found[k]);
 			vim_free(exp_path);
-			vim_free(halved_slash);
+			if (halved_slash != path)
+			    vim_free(halved_slash);
 		    }
 		    else
 			// Expansion was done here, file names are literal.