diff src/eval.c @ 13244:ac42c4b11dbc v8.0.1496

patch 8.0.1496: clearing a pointer takes two lines commit https://github.com/vim/vim/commit/d23a823669d93fb2a570a039173eefe4856ac806 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 10 18:45:26 2018 +0100 patch 8.0.1496: clearing a pointer takes two lines Problem: Clearing a pointer takes two lines. Solution: Add VIM_CLEAR() and replace vim_clear(). (Hirohito Higashi, closes #2629)
author Christian Brabandt <cb@256bit.org>
date Sat, 10 Feb 2018 19:00:07 +0100
parents 6e81a68d63a1
children 69278c25429d
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -361,10 +361,7 @@ eval_clear(void)
     {
 	p = &vimvars[i];
 	if (p->vv_di.di_tv.v_type == VAR_STRING)
-	{
-	    vim_free(p->vv_str);
-	    p->vv_str = NULL;
-	}
+	    VIM_CLEAR(p->vv_str);
 	else if (p->vv_di.di_tv.v_type == VAR_LIST)
 	{
 	    list_unref(p->vv_list);
@@ -569,14 +566,11 @@ var_redir_stop(void)
 	}
 
 	/* free the collected output */
-	vim_free(redir_ga.ga_data);
-	redir_ga.ga_data = NULL;
-
-	vim_free(redir_lval);
-	redir_lval = NULL;
-    }
-    vim_free(redir_varname);
-    redir_varname = NULL;
+	VIM_CLEAR(redir_ga.ga_data);
+
+	VIM_CLEAR(redir_lval);
+    }
+    VIM_CLEAR(redir_varname);
 }
 
 # if defined(FEAT_MBYTE) || defined(PROTO)
@@ -1009,10 +1003,7 @@ eval_expr(char_u *arg, char_u **nextcmd)
 
     tv = (typval_T *)alloc(sizeof(typval_T));
     if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL)
-    {
-	vim_free(tv);
-	tv = NULL;
-    }
+	VIM_CLEAR(tv);
 
     return tv;
 }
@@ -3213,8 +3204,7 @@ get_user_var_name(expand_T *xp, int idx)
     if (vidx < VV_LEN)
 	return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name);
 
-    vim_free(varnamebuf);
-    varnamebuf = NULL;
+    VIM_CLEAR(varnamebuf);
     varnamebuflen = 0;
     return NULL;
 }
@@ -6096,10 +6086,7 @@ get_env_tv(char_u **arg, typval_T *rettv
 	    /* next try expanding things like $VIM and ${HOME} */
 	    string = expand_env_save(name - 1);
 	    if (string != NULL && *string == '$')
-	    {
-		vim_free(string);
-		string = NULL;
-	    }
+		VIM_CLEAR(string);
 	}
 	name[len] = cc;
 
@@ -7116,8 +7103,7 @@ clear_tv(typval_T *varp)
 		func_unref(varp->vval.v_string);
 		/* FALLTHROUGH */
 	    case VAR_STRING:
-		vim_free(varp->vval.v_string);
-		varp->vval.v_string = NULL;
+		VIM_CLEAR(varp->vval.v_string);
 		break;
 	    case VAR_PARTIAL:
 		partial_unref(varp->vval.v_partial);