diff src/vim9execute.c @ 30092:53e7e912eeec v9.0.0382

patch 9.0.0382: freeing the wrong string on failure Commit: https://github.com/vim/vim/commit/31ea6bf530a814991f669122dbc9921117a862c3 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Sep 5 10:47:13 2022 +0100 patch 9.0.0382: freeing the wrong string on failure Problem: Freeing the wrong string on failure. Solution: Adjust the argument. Reorder the code.
author Bram Moolenaar <Bram@vim.org>
date Mon, 05 Sep 2022 12:00:06 +0200
parents a542dfb1c1a2
children 458162398682
line wrap: on
line diff
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -937,21 +937,22 @@ add_defer_function(char_u *name, int arg
     if (dfunc->df_defer_var_idx == 0)
     {
 	iemsg("df_defer_var_idx is zero");
-	vim_free(func_tv.vval.v_string);
+	vim_free(name);
 	return FAIL;
     }
-    func_tv.v_type = VAR_FUNC;
-    func_tv.v_lock = 0;
-    func_tv.vval.v_string = name;
 
     l = add_defer_item(dfunc->df_defer_var_idx - 1, 1, current_ectx);
     if (l == NULL)
     {
-	vim_free(func_tv.vval.v_string);
+	vim_free(name);
 	return FAIL;
     }
 
+    func_tv.v_type = VAR_FUNC;
+    func_tv.v_lock = 0;
+    func_tv.vval.v_string = name;
     list_set_item(l, 0, &func_tv);
+
     for (i = 0; i < argcount; ++i)
 	list_set_item(l, i + 1, argvars + i);
     return OK;