]> granicus.if.org Git - vim/commitdiff
patch 8.1.1897: may free memory twice when out of memory v8.1.1897
authorBram Moolenaar <Bram@vim.org>
Wed, 21 Aug 2019 10:54:18 +0000 (12:54 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 21 Aug 2019 10:54:18 +0000 (12:54 +0200)
Problem:    May free memory twice when out of memory.
Solution:   Check that backslash_halve_save() returns a different pointer.
            (Dominique Pelle, closes #4847)

src/cmdexpand.c
src/misc1.c
src/version.c

index 1454fd2f53c96034e13a70f64e4e5edf81530ae4..59d84419c61d2848bb9a957a8346c5ce17c454a7 100644 (file)
@@ -646,17 +646,19 @@ showmatches(expand_T *xp, int wildmenu UNUSED)
                    {
                        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.
index 4884f6cb53fae843ab478061366effa1257fcc87..5f0a7b6c34cef1b076724c226cec6ba94f4abb56 100644 (file)
@@ -4086,7 +4086,9 @@ gen_expand_wildcards(
                addfile(&ga, t, flags | EW_DIR | EW_FILE);
            else
                addfile(&ga, t, flags);
-           vim_free(t);
+
+           if (t != p)
+               vim_free(t);
        }
 
 #if defined(FEAT_SEARCHPATH)
index 81e0d5a2da45157dc0dde7780902cdbbcf3a38ef..14a9528bc6839d4d091c784da7d96a48e29f7c98 100644 (file)
@@ -765,6 +765,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1897,
 /**/
     1896,
 /**/