diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-05-22 01:02:26 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-05-25 10:07:05 +0200 |
commit | ae846b41dfed16446be6469cb01f12f1eb1fa534 (patch) | |
tree | 2851845f2faf61d5945cb4f1d8761316201a6246 | |
parent | a9d7ec4587d8eb20f12ebecc427ad818fb0e4971 (diff) | |
download | rneovim-ae846b41dfed16446be6469cb01f12f1eb1fa534.tar.gz rneovim-ae846b41dfed16446be6469cb01f12f1eb1fa534.tar.bz2 rneovim-ae846b41dfed16446be6469cb01f12f1eb1fa534.zip |
vim-patch:8.0.1496: VIM_CLEAR()
Problem: Clearing a pointer takes two lines.
Solution: Add VIM_CLEAR() and replace vim_clear(). (Hirohito Higashi,
closes #2629)
vim-patch:8.0.1481
36 files changed, 165 insertions, 306 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 8a3d4ad418..a5ad1f1a11 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -809,8 +809,7 @@ free_buffer_stuff( bufhl_clear_all(buf); // delete any highligts map_clear_int(buf, MAP_ALL_MODES, true, false); // clear local mappings map_clear_int(buf, MAP_ALL_MODES, true, true); // clear local abbrevs - xfree(buf->b_start_fenc); - buf->b_start_fenc = NULL; + XFREE_CLEAR(buf->b_start_fenc); buf_updates_unregister_all(buf); } @@ -1756,10 +1755,8 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags) buf->b_wininfo = xcalloc(1, sizeof(wininfo_T)); if (ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL)) { - xfree(buf->b_ffname); - buf->b_ffname = NULL; - xfree(buf->b_sfname); - buf->b_sfname = NULL; + XFREE_CLEAR(buf->b_ffname); + XFREE_CLEAR(buf->b_sfname); if (buf != curbuf) { free_buffer(buf); } @@ -2665,10 +2662,8 @@ setfname( if (ffname == NULL || *ffname == NUL) { // Removing the name. - xfree(buf->b_ffname); - xfree(buf->b_sfname); - buf->b_ffname = NULL; - buf->b_sfname = NULL; + XFREE_CLEAR(buf->b_ffname); + XFREE_CLEAR(buf->b_sfname); } else { fname_expand(buf, &ffname, &sfname); // will allocate ffname if (ffname == NULL) { // out of memory @@ -3791,8 +3786,7 @@ int build_stl_str_hl( if (str != NULL && *str != 0) { if (*skipdigits(str) == NUL) { num = atoi((char *)str); - xfree(str); - str = NULL; + XFREE_CLEAR(str); itemisflag = false; } } diff --git a/src/nvim/diff.c b/src/nvim/diff.c index ee4a48ff5d..f720e702a4 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -662,8 +662,7 @@ static void diff_redraw(int dofold) static void clear_diffin(diffin_T *din) { if (din->din_fname == NULL) { - xfree(din->din_mmfile.ptr); - din->din_mmfile.ptr = NULL; + XFREE_CLEAR(din->din_mmfile.ptr); } else { os_remove((char *)din->din_fname); } diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 49bc2ab2f0..5fbe2c2eb6 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2522,8 +2522,7 @@ static void ins_compl_del_pum(void) { if (compl_match_array != NULL) { pum_undisplay(false); - xfree(compl_match_array); - compl_match_array = NULL; + XFREE_CLEAR(compl_match_array); } } @@ -2592,8 +2591,7 @@ void ins_compl_show_pum(void) * not use "compl_leader" as prefix filter. */ if (ins_compl_need_restart()){ - xfree(compl_leader); - compl_leader = NULL; + XFREE_CLEAR(compl_leader); } if (compl_leader != NULL) lead_len = (int)STRLEN(compl_leader); @@ -2960,10 +2958,8 @@ static void ins_compl_free(void) compl_T *match; int i; - xfree(compl_pattern); - compl_pattern = NULL; - xfree(compl_leader); - compl_leader = NULL; + XFREE_CLEAR(compl_pattern); + XFREE_CLEAR(compl_leader); if (compl_first_match == NULL) return; @@ -2993,13 +2989,10 @@ static void ins_compl_clear(void) compl_cont_status = 0; compl_started = FALSE; compl_matches = 0; - xfree(compl_pattern); - compl_pattern = NULL; - xfree(compl_leader); - compl_leader = NULL; + XFREE_CLEAR(compl_pattern); + XFREE_CLEAR(compl_leader); edit_submode_extra = NULL; - xfree(compl_orig_text); - compl_orig_text = NULL; + XFREE_CLEAR(compl_orig_text); compl_enter_selects = FALSE; // clear v:completed_item set_vim_var_dict(VV_COMPLETED_ITEM, tv_dict_alloc()); @@ -4960,10 +4953,8 @@ static int ins_complete(int c, bool enable_pum) compl_orig_text = vim_strnsave(line + compl_col, compl_length); if (ins_compl_add(compl_orig_text, -1, p_ic, NULL, NULL, false, 0, ORIGINAL_TEXT, false, false) != OK) { - xfree(compl_pattern); - compl_pattern = NULL; - xfree(compl_orig_text); - compl_orig_text = NULL; + XFREE_CLEAR(compl_pattern); + XFREE_CLEAR(compl_orig_text); return FAIL; } @@ -6310,10 +6301,8 @@ void set_last_insert(int c) #if defined(EXITFREE) void free_last_insert(void) { - xfree(last_insert); - last_insert = NULL; - xfree(compl_orig_text); - compl_orig_text = NULL; + XFREE_CLEAR(last_insert); + XFREE_CLEAR(compl_orig_text); } #endif @@ -6840,8 +6829,7 @@ static void mb_replace_pop_ins(int cc) */ static void replace_flush(void) { - xfree(replace_stack); - replace_stack = NULL; + XFREE_CLEAR(replace_stack); replace_stack_len = 0; replace_stack_nr = 0; } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index de510a8bca..12e309bfdc 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -622,8 +622,7 @@ void eval_clear(void) for (size_t i = 0; i < ARRAY_SIZE(vimvars); i++) { p = &vimvars[i]; if (p->vv_di.di_tv.v_type == VAR_STRING) { - xfree(p->vv_str); - p->vv_str = NULL; + XFREE_CLEAR(p->vv_str); } else if (p->vv_di.di_tv.v_type == VAR_LIST) { tv_list_unref(p->vv_list); p->vv_list = NULL; @@ -842,15 +841,12 @@ void var_redir_stop(void) clear_lval(redir_lval); } - /* free the collected output */ - xfree(redir_ga.ga_data); - redir_ga.ga_data = NULL; + // free the collected output + XFREE_CLEAR(redir_ga.ga_data); - xfree(redir_lval); - redir_lval = NULL; + XFREE_CLEAR(redir_lval); } - xfree(redir_varname); - redir_varname = NULL; + XFREE_CLEAR(redir_varname); } int eval_charconvert(const char *const enc_from, const char *const enc_to, @@ -3201,8 +3197,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name); } - xfree(varnamebuf); - varnamebuf = NULL; + XFREE_CLEAR(varnamebuf); varnamebuflen = 0; return NULL; } @@ -5942,8 +5937,7 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate) // Next try expanding things like $VIM and ${HOME}. string = expand_env_save(name - 1); if (string != NULL && *string == '$') { - xfree(string); - string = NULL; + XFREE_CLEAR(string); } } name[len] = cc; @@ -13815,8 +13809,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (*q != NUL) { STRMOVE(remain, q - 1); } else { - xfree(remain); - remain = NULL; + XFREE_CLEAR(remain); } } @@ -20391,8 +20384,7 @@ void ex_function(exarg_T *eap) /* between ":append" and "." and between ":python <<EOF" and "EOF" * don't check for ":endfunc". */ if (STRCMP(theline, skip_until) == 0) { - xfree(skip_until); - skip_until = NULL; + XFREE_CLEAR(skip_until); } } else { /* skip ':' and blanks*/ @@ -20550,8 +20542,7 @@ void ex_function(exarg_T *eap) // redefine existing function ga_clear_strings(&(fp->uf_args)); ga_clear_strings(&(fp->uf_lines)); - xfree(name); - name = NULL; + XFREE_CLEAR(name); } } } else { diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index b3933ac9a6..180ebaf769 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3526,8 +3526,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, lnum += regmatch.startpos[0].lnum; sub_firstlnum += regmatch.startpos[0].lnum; nmatch -= regmatch.startpos[0].lnum; - xfree(sub_firstline); - sub_firstline = NULL; + XFREE_CLEAR(sub_firstline); } // Now we're at the line where the pattern match starts @@ -4058,11 +4057,11 @@ skip: line_breakcheck(); } - if (did_sub) + if (did_sub) { ++sub_nlines; - xfree(new_start); /* for when substitute was cancelled */ - xfree(sub_firstline); /* free the copy of the original line */ - sub_firstline = NULL; + } + xfree(new_start); // for when substitute was cancelled + XFREE_CLEAR(sub_firstline); // free the copy of the original line } line_breakcheck(); @@ -5077,9 +5076,8 @@ void fix_help_buffer(void) } if (fnamecmp(e1, ".txt") != 0 && fnamecmp(e1, fname + 4) != 0) { - /* Not .txt and not .abx, remove it. */ - xfree(fnames[i1]); - fnames[i1] = NULL; + // Not .txt and not .abx, remove it. + XFREE_CLEAR(fnames[i1]); continue; } if (e1 - f1 != e2 - f2 @@ -5088,9 +5086,8 @@ void fix_help_buffer(void) } if (fnamecmp(e1, ".txt") == 0 && fnamecmp(e2, fname + 4) == 0) { - /* use .abx instead of .txt */ - xfree(fnames[i1]); - fnames[i1] = NULL; + // use .abx instead of .txt + XFREE_CLEAR(fnames[i1]); } } } diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index a2ed37e37e..3202f82a29 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -1040,12 +1040,9 @@ static void profile_reset(void) uf->uf_tm_self = profile_zero(); uf->uf_tm_children = profile_zero(); - xfree(uf->uf_tml_count); - xfree(uf->uf_tml_total); - xfree(uf->uf_tml_self); - uf->uf_tml_count = NULL; - uf->uf_tml_total = NULL; - uf->uf_tml_self = NULL; + XFREE_CLEAR(uf->uf_tml_count); + XFREE_CLEAR(uf->uf_tml_total); + XFREE_CLEAR(uf->uf_tml_self); uf->uf_tml_start = profile_zero(); uf->uf_tml_children = profile_zero(); @@ -1056,8 +1053,7 @@ static void profile_reset(void) } } - xfree(profile_fname); - profile_fname = NULL; + XFREE_CLEAR(profile_fname); } /// Start profiling a script. @@ -4003,8 +3999,7 @@ void free_locales(void) for (i = 0; locales[i] != NULL; i++) { xfree(locales[i]); } - xfree(locales); - locales = NULL; + XFREE_CLEAR(locales); } } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 9c4a3f389a..979daf24fe 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -431,8 +431,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, if (cstack.cs_looplevel > 0 && current_line < lines_ga.ga_len) { /* Each '|' separated command is stored separately in lines_ga, to * be able to jump to it. Don't use next_cmdline now. */ - xfree(cmdline_copy); - cmdline_copy = NULL; + XFREE_CLEAR(cmdline_copy); /* Check if a function has returned or, unless it has an unclosed * try conditional, aborted. */ @@ -606,12 +605,11 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, current_line = cmd_loop_cookie.current_line; if (next_cmdline == NULL) { - xfree(cmdline_copy); - cmdline_copy = NULL; - /* - * If the command was typed, remember it for the ':' register. - * Do this AFTER executing the command to make :@: work. - */ + XFREE_CLEAR(cmdline_copy); + // + // If the command was typed, remember it for the ':' register. + // Do this AFTER executing the command to make :@: work. + // if (getline_equal(fgetline, cookie, getexline) && new_last_cmdline != NULL) { xfree(last_cmdline); @@ -4842,10 +4840,8 @@ static int uc_add_command(char_u *name, size_t name_len, char_u *rep, goto fail; } - xfree(cmd->uc_rep); - cmd->uc_rep = NULL; - xfree(cmd->uc_compl_arg); - cmd->uc_compl_arg = NULL; + XFREE_CLEAR(cmd->uc_rep); + XFREE_CLEAR(cmd->uc_compl_arg); break; } @@ -7232,11 +7228,8 @@ static char_u *prev_dir = NULL; #if defined(EXITFREE) void free_cd_dir(void) { - xfree(prev_dir); - prev_dir = NULL; - - xfree(globaldir); - globaldir = NULL; + XFREE_CLEAR(prev_dir); + XFREE_CLEAR(globaldir); } #endif @@ -7247,13 +7240,11 @@ void free_cd_dir(void) void post_chdir(CdScope scope, bool trigger_dirchanged) { // Always overwrite the window-local CWD. - xfree(curwin->w_localdir); - curwin->w_localdir = NULL; + XFREE_CLEAR(curwin->w_localdir); // Overwrite the tab-local CWD for :cd, :tcd. if (scope >= kCdScopeTab) { - xfree(curtab->tp_localdir); - curtab->tp_localdir = NULL; + XFREE_CLEAR(curtab->tp_localdir); } if (scope < kCdScopeGlobal) { @@ -7270,8 +7261,7 @@ void post_chdir(CdScope scope, bool trigger_dirchanged) switch (scope) { case kCdScopeGlobal: // We are now in the global directory, no need to remember its name. - xfree(globaldir); - globaldir = NULL; + XFREE_CLEAR(globaldir); break; case kCdScopeTab: curtab->tp_localdir = (char_u *)xstrdup(cwd); diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index b16023b0ec..beac3cd9ec 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -592,8 +592,7 @@ static int command_line_execute(VimState *state, int key) && s->c != K_KPAGEDOWN && s->c != K_KPAGEUP && s->c != K_LEFT && s->c != K_RIGHT && (s->xpc.xp_numfiles > 0 || (s->c != Ctrl_P && s->c != Ctrl_N))) { - xfree(s->lookfor); - s->lookfor = NULL; + XFREE_CLEAR(s->lookfor); } // When there are matching completions to select <S-Tab> works like @@ -626,8 +625,7 @@ static int command_line_execute(VimState *state, int key) && s->c != Ctrl_L) { if (compl_match_array) { pum_undisplay(true); - xfree(compl_match_array); - compl_match_array = NULL; + XFREE_CLEAR(compl_match_array); } if (s->xpc.xp_numfiles != -1) { (void)ExpandOne(&s->xpc, NULL, NULL, 0, WILD_FREE); @@ -1260,8 +1258,7 @@ static int command_line_handle_key(CommandLineState *s) return command_line_not_changed(s); } - xfree(ccline.cmdbuff); // no commandline to return - ccline.cmdbuff = NULL; + XFREE_CLEAR(ccline.cmdbuff); // no commandline to return if (!cmd_silent && !ui_has(kUICmdline)) { if (cmdmsg_rl) { msg_col = Columns; @@ -1978,8 +1975,7 @@ static int command_line_changed(CommandLineState *s) /// Abandon the command line. static void abandon_cmdline(void) { - xfree(ccline.cmdbuff); - ccline.cmdbuff = NULL; + XFREE_CLEAR(ccline.cmdbuff); if (msg_scrolled == 0) { compute_cmdrow(); } @@ -2630,8 +2626,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline) if (colored_ccline->cmdbuff == NULL || *colored_ccline->cmdbuff == NUL) { // Nothing to do, exiting. - xfree(ccline_colors->cmdbuff); - ccline_colors->cmdbuff = NULL; + XFREE_CLEAR(ccline_colors->cmdbuff); return ret; } @@ -3650,8 +3645,7 @@ nextwild ( } } if ((int)STRLEN(p2) < j) { - xfree(p2); - p2 = NULL; + XFREE_CLEAR(p2); } } } @@ -3785,8 +3779,7 @@ ExpandOne ( if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) { FreeWild(xp->xp_numfiles, xp->xp_files); xp->xp_numfiles = -1; - xfree(orig_save); - orig_save = NULL; + XFREE_CLEAR(orig_save); } findex = 0; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index b468b7bb8c..3c45a1ad2e 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -885,8 +885,7 @@ retry: } if (tmpname != NULL) { os_remove((char *)tmpname); // delete converted file - xfree(tmpname); - tmpname = NULL; + XFREE_CLEAR(tmpname); } } @@ -1884,8 +1883,7 @@ failed: msg_add_lines(c, (long)linecnt, filesize); - xfree(keep_msg); - keep_msg = NULL; + XFREE_CLEAR(keep_msg); p = NULL; msg_scrolled_ign = TRUE; @@ -2171,8 +2169,7 @@ readfile_charconvert ( MSG(errmsg); if (tmpname != NULL) { os_remove((char *)tmpname); // delete converted file - xfree(tmpname); - tmpname = NULL; + XFREE_CLEAR(tmpname); } } @@ -2828,14 +2825,13 @@ buf_write ( */ if (os_fileinfo((char *)backup, &file_info_new)) { if (os_fileinfo_id_equal(&file_info_new, &file_info_old)) { - /* - * Backup file is same as original file. - * May happen when modname() gave the same file back (e.g. silly - * link). If we don't check here, we either ruin the file when - * copying or erase it after writing. - */ - xfree(backup); - backup = NULL; /* no backup file to delete */ + // + // Backup file is same as original file. + // May happen when modname() gave the same file back (e.g. silly + // link). If we don't check here, we either ruin the file when + // copying or erase it after writing. + // + XFREE_CLEAR(backup); // no backup file to delete } else if (!p_bk) { /* * We are not going to keep the backup file, so don't @@ -2853,8 +2849,7 @@ buf_write ( } /* They all exist??? Must be something wrong. */ if (*wp == 'a') { - xfree(backup); - backup = NULL; + XFREE_CLEAR(backup); } } } @@ -2969,8 +2964,7 @@ nobackup: } // They all exist??? Must be something wrong! if (*p == 'a') { - xfree(backup); - backup = NULL; + XFREE_CLEAR(backup); } } } @@ -2988,8 +2982,7 @@ nobackup: if (vim_rename(fname, backup) == 0) break; - xfree(backup); /* don't do the rename below */ - backup = NULL; + XFREE_CLEAR(backup); // don't do the rename below } } if (backup == NULL && !forceit) { @@ -3585,8 +3578,7 @@ restore_backup: EMSG(_("E205: Patchmode: can't save original file")); } else if (!os_path_exists((char_u *)org)) { vim_rename(backup, (char_u *)org); - xfree(backup); /* don't delete the file */ - backup = NULL; + XFREE_CLEAR(backup); // don't delete the file #ifdef UNIX set_file_time((char_u *)org, file_info_old.stat.st_atim.tv_sec, @@ -4313,8 +4305,7 @@ void shorten_buf_fname(buf_T *buf, char_u *dirname, int force) && (force || buf->b_sfname == NULL || path_is_absolute(buf->b_sfname))) { - xfree(buf->b_sfname); - buf->b_sfname = NULL; + XFREE_CLEAR(buf->b_sfname); p = path_shorten_fname(buf->b_ffname, dirname); if (p != NULL) { buf->b_sfname = vim_strsave(p); @@ -5352,8 +5343,7 @@ void vim_deltempdir(void) // remove the trailing path separator path_tail(vim_tempdir)[-1] = NUL; delete_recursive((const char *)vim_tempdir); - xfree(vim_tempdir); - vim_tempdir = NULL; + XFREE_CLEAR(vim_tempdir); } } @@ -5512,8 +5502,7 @@ static void show_autocmd(AutoPat *ap, event_T event) // Mark an autocommand handler for deletion. static void au_remove_pat(AutoPat *ap) { - xfree(ap->pat); - ap->pat = NULL; + XFREE_CLEAR(ap->pat); ap->buflocal_nr = -1; au_need_clean = true; } @@ -5522,8 +5511,7 @@ static void au_remove_pat(AutoPat *ap) static void au_remove_cmds(AutoPat *ap) { for (AutoCmd *ac = ap->cmds; ac != NULL; ac = ac->next) { - xfree(ac->cmd); - ac->cmd = NULL; + XFREE_CLEAR(ac->cmd); } au_need_clean = true; } @@ -5531,8 +5519,7 @@ static void au_remove_cmds(AutoPat *ap) // Delete one command from an autocmd pattern. static void au_del_cmd(AutoCmd *ac) { - xfree(ac->cmd); - ac->cmd = NULL; + XFREE_CLEAR(ac->cmd); au_need_clean = true; } @@ -6504,8 +6491,7 @@ void aucmd_prepbuf(aco_save_T *aco, buf_T *buf) /* Make sure w_localdir and globaldir are NULL to avoid a chdir() in * win_enter_ext(). */ - xfree(aucmd_win->w_localdir); - aucmd_win->w_localdir = NULL; + XFREE_CLEAR(aucmd_win->w_localdir); aco->globaldir = globaldir; globaldir = NULL; @@ -7128,8 +7114,7 @@ auto_next_pat ( AutoCmd *cp; char *s; - xfree(sourcing_name); - sourcing_name = NULL; + XFREE_CLEAR(sourcing_name); for (ap = apc->curpat; ap != NULL && !got_int; ap = ap->next) { apc->curpat = NULL; @@ -7737,12 +7722,12 @@ char_u * file_pat_to_reg_pat( reg_pat[i++] = '$'; reg_pat[i] = NUL; if (nested != 0) { - if (nested < 0) + if (nested < 0) { EMSG(_("E219: Missing {.")); - else + } else { EMSG(_("E220: Missing }.")); - xfree(reg_pat); - reg_pat = NULL; + } + XFREE_CLEAR(reg_pat); } return reg_pat; } diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 983dbb7bbe..bf2ac35554 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -1942,8 +1942,7 @@ void mch_print_cleanup(void) prt_file_error = FALSE; } if (prt_ps_file_name != NULL) { - xfree(prt_ps_file_name); - prt_ps_file_name = NULL; + XFREE_CLEAR(prt_ps_file_name); } } diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 8b6fd6c705..2423fdcdae 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -1531,10 +1531,8 @@ static void cs_fill_results(char *tagstr, size_t totmatches, int *nummatches_a, if (totsofar == 0) { /* No matches, free the arrays and return NULL in "*matches_p". */ - xfree(matches); - matches = NULL; - xfree(cntxts); - cntxts = NULL; + XFREE_CLEAR(matches); + XFREE_CLEAR(cntxts); } *matched = totsofar; *matches_p = matches; diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 5c9367ab01..7809b6814f 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -523,8 +523,7 @@ static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf) && fm->fname != NULL && fnamecmp(name, fm->fname) == 0) { fm->fmark.fnum = buf->b_fnum; - xfree(fm->fname); - fm->fname = NULL; + XFREE_CLEAR(fm->fname); } } @@ -752,8 +751,7 @@ void ex_delmarks(exarg_T *eap) n = i - 'A'; } namedfm[n].fmark.mark.lnum = 0; - xfree(namedfm[n].fname); - namedfm[n].fname = NULL; + XFREE_CLEAR(namedfm[n].fname); } } } else diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 8cc91146cc..c161bad66f 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -1421,8 +1421,7 @@ int utf16_to_utf8(const wchar_t *strw, char **str) NULL, NULL); if (utf8_len == 0) { - xfree(*str); - *str = NULL; + XFREE_CLEAR(*str); return GetLastError(); } (*str)[utf8_len] = '\0'; @@ -2119,9 +2118,8 @@ static char_u *iconv_string(const vimconv_T *const vcp, char_u *str, from += l; fromlen -= l; } else if (ICONV_ERRNO != ICONV_E2BIG) { - /* conversion failed */ - xfree(result); - result = NULL; + // conversion failed + XFREE_CLEAR(result); break; } /* Not enough room or skipping illegal sequence. */ diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 5a64c82e0e..7bed644da3 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -719,10 +719,8 @@ blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr) /// Frees mf_fname and mf_ffname. void mf_free_fnames(memfile_T *mfp) { - xfree(mfp->mf_fname); - xfree(mfp->mf_ffname); - mfp->mf_fname = NULL; - mfp->mf_ffname = NULL; + XFREE_CLEAR(mfp->mf_fname); + XFREE_CLEAR(mfp->mf_ffname); } /// Set the simple file name and the full file name of memfile's swapfile, out diff --git a/src/nvim/memline.c b/src/nvim/memline.c index a071314453..c0a47054cc 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -563,8 +563,7 @@ void ml_close(buf_T *buf, int del_file) if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY)) xfree(buf->b_ml.ml_line_ptr); xfree(buf->b_ml.ml_stack); - xfree(buf->b_ml.ml_chunksize); - buf->b_ml.ml_chunksize = NULL; + XFREE_CLEAR(buf->b_ml.ml_chunksize); buf->b_ml.ml_mfp = NULL; /* Reset the "recovered" flag, give the ATTENTION prompt the next time @@ -3344,8 +3343,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, if (fname == NULL) /* must be out of memory */ break; if ((n = strlen(fname)) == 0) { /* safety check */ - xfree(fname); - fname = NULL; + XFREE_CLEAR(fname); break; } // check if the swapfile already exists @@ -3541,8 +3539,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, if (fname[n - 1] == 'a') { /* ".s?a" */ if (fname[n - 2] == 'a') { /* ".saa": tried enough, give up */ EMSG(_("E326: Too many swap files found")); - xfree(fname); - fname = NULL; + XFREE_CLEAR(fname); break; } --fname[n - 2]; /* ".svz", ".suz", etc. */ diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 472481bb30..368faf7d0b 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -388,8 +388,7 @@ add_menu_path( menup = &menu->children; parent = menu; name = next_name; - xfree(dname); - dname = NULL; + XFREE_CLEAR(dname); if (pri_tab[pri_idx + 1] != -1) { pri_idx++; } diff --git a/src/nvim/message.c b/src/nvim/message.c index cb83d6482c..20f63773fe 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -420,8 +420,7 @@ static char_u *last_sourcing_name = NULL; */ void reset_last_sourcing(void) { - xfree(last_sourcing_name); - last_sourcing_name = NULL; + XFREE_CLEAR(last_sourcing_name); last_sourcing_lnum = 0; } @@ -1117,8 +1116,7 @@ void wait_return(int redraw) reset_last_sourcing(); if (keep_msg != NULL && vim_strsize(keep_msg) >= (Rows - cmdline_row - 1) * Columns + sc_col) { - xfree(keep_msg); - keep_msg = NULL; /* don't redisplay message, it's too long */ + XFREE_CLEAR(keep_msg); // don't redisplay message, it's too long } if (tmpState == SETWSIZE) { /* got resize event while in vgetc() */ @@ -1188,8 +1186,7 @@ void msg_start(void) int did_return = FALSE; if (!msg_silent) { - xfree(keep_msg); - keep_msg = NULL; /* don't display old message now */ + XFREE_CLEAR(keep_msg); // don't display old message now } if (need_clr_eos) { @@ -3001,8 +2998,7 @@ void give_warning(char_u *message, bool hl) FUNC_ATTR_NONNULL_ARG(1) ++no_wait_return; set_vim_var_string(VV_WARNINGMSG, (char *) message, -1); - xfree(keep_msg); - keep_msg = NULL; + XFREE_CLEAR(keep_msg); if (hl) { keep_msg_attr = HL_ATTR(HLF_W); } else { diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 0008409731..ee870b7224 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -2828,8 +2828,7 @@ char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags, os_remove((char *)tempname); if (i != len) { EMSG2(_(e_notread), tempname); - xfree(buffer); - buffer = NULL; + XFREE_CLEAR(buffer); } else if (ret_len == NULL) { /* Change NUL into SOH, otherwise the string is truncated. */ for (i = 0; i < len; ++i) diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 04eede18bd..50abd226fc 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1467,8 +1467,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) } else { AppendToRedobuffLit(repeat_cmdline, -1); AppendToRedobuff(NL_STR); - xfree(repeat_cmdline); - repeat_cmdline = NULL; + XFREE_CLEAR(repeat_cmdline); } } } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 216bab4dda..1c5d4e98a7 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -983,9 +983,8 @@ do_execreg( EMSG(_(e_nolastcmd)); return FAIL; } - xfree(new_last_cmdline); /* don't keep the cmdline containing @: */ - new_last_cmdline = NULL; - /* Escape all control characters with a CTRL-V */ + XFREE_CLEAR(new_last_cmdline); // don't keep the cmdline containing @: + // Escape all control characters with a CTRL-V p = vim_strsave_escaped_ext( last_cmdline, (char_u *) @@ -2348,8 +2347,7 @@ void free_register(yankreg_T *reg) for (size_t i = reg->y_size; i-- > 0;) { // from y_size - 1 to 0 included xfree(reg->y_array[i]); } - xfree(reg->y_array); - reg->y_array = NULL; + XFREE_CLEAR(reg->y_array); } } diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index 8180a2e8ac..35a7942059 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -553,8 +553,7 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, *num_file = j; if (*num_file == 0) { // rejected all entries - xfree(*file); - *file = NULL; + XFREE_CLEAR(*file); goto notfound; } diff --git a/src/nvim/path.c b/src/nvim/path.c index 67b88a861a..b43a172991 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2088,8 +2088,7 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_files, char_u ***files, // Free empty array of matches if (*num_files == 0) { - xfree(*files); - *files = NULL; + XFREE_CLEAR(*files); return FAIL; } diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 550f742106..8036d3e3bc 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -848,8 +848,7 @@ qf_init_ext( int status; // Do not used the cached buffer, it may have been wiped out. - xfree(qf_last_bufname); - qf_last_bufname = NULL; + XFREE_CLEAR(qf_last_bufname); memset(&state, 0, sizeof(state)); memset(&fields, 0, sizeof(fields)); @@ -894,8 +893,7 @@ qf_init_ext( // parsed values. if (last_efm == NULL || (STRCMP(last_efm, efm) != 0)) { // free the previously parsed data - xfree(last_efm); - last_efm = NULL; + XFREE_CLEAR(last_efm); free_efm_list(&fmt_first); // parse the current 'efm' @@ -1019,8 +1017,7 @@ qf_init_end: /// Prepends ':' to the title. static void qf_store_title(qf_info_T *qi, int qf_idx, char_u *title) { - xfree(qi->qf_lists[qf_idx].qf_title); - qi->qf_lists[qf_idx].qf_title = NULL; + XFREE_CLEAR(qi->qf_lists[qf_idx].qf_title); if (title != NULL) { size_t len = STRLEN(title) + 1; @@ -2754,8 +2751,7 @@ static void qf_free(qf_info_T *qi, int idx) qf_list_T *qfl = &qi->qf_lists[idx]; qf_free_items(qi, idx); - xfree(qfl->qf_title); - qfl->qf_title = NULL; + XFREE_CLEAR(qfl->qf_title); tv_free(qfl->qf_ctx); qfl->qf_ctx = NULL; qfl->qf_id = 0; diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 39ce7ff844..8598da6376 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3550,8 +3550,7 @@ theend: /* Free "reg_tofree" when it's a bit big. * Free regstack and backpos if they are bigger than their initial size. */ if (reg_tofreelen > 400) { - xfree(reg_tofree); - reg_tofree = NULL; + XFREE_CLEAR(reg_tofree); } if (regstack.ga_maxlen > REGSTACK_INITIAL) ga_clear(®stack); @@ -6618,8 +6617,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, if (eval_result != NULL) { STRCPY(dest, eval_result); dst += STRLEN(eval_result); - xfree(eval_result); - eval_result = NULL; + XFREE_CLEAR(eval_result); } } else { int prev_can_f_submatch = can_f_submatch; diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index ce7270ae65..dc1ab971ab 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -6594,8 +6594,7 @@ out: return (regprog_T *)prog; fail: - xfree(prog); - prog = NULL; + XFREE_CLEAR(prog); #ifdef REGEXP_DEBUG nfa_postfix_dump(expr, FAIL); #endif diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 4c830bb256..81ddbbfb74 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3135,8 +3135,7 @@ win_line ( int c0; if (p_extra_free != NULL) { - xfree(p_extra_free); - p_extra_free = NULL; + XFREE_CLEAR(p_extra_free); } // Get a character from the line itself. diff --git a/src/nvim/search.c b/src/nvim/search.c index 6e00602e66..605d9383a7 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -4290,8 +4290,7 @@ find_pattern_in_path( prev_fname = NULL; } } - xfree(new_fname); - new_fname = NULL; + XFREE_CLEAR(new_fname); already_searched = TRUE; break; } diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 4440d3905f..4aafc669dc 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1358,8 +1358,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) case kSDItemGlobalMark: { buf_T *buf = find_buffer(&fname_bufs, cur_entry.data.filemark.fname); if (buf != NULL) { - xfree(cur_entry.data.filemark.fname); - cur_entry.data.filemark.fname = NULL; + XFREE_CLEAR(cur_entry.data.filemark.fname); } xfmark_T fm = (xfmark_T) { .fname = (char_u *) (buf == NULL diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 0fc33bec81..6fd22a6537 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1708,19 +1708,13 @@ void slang_clear(slang_T *lp) { garray_T *gap; - xfree(lp->sl_fbyts); - lp->sl_fbyts = NULL; - xfree(lp->sl_kbyts); - lp->sl_kbyts = NULL; - xfree(lp->sl_pbyts); - lp->sl_pbyts = NULL; - - xfree(lp->sl_fidxs); - lp->sl_fidxs = NULL; - xfree(lp->sl_kidxs); - lp->sl_kidxs = NULL; - xfree(lp->sl_pidxs); - lp->sl_pidxs = NULL; + XFREE_CLEAR(lp->sl_fbyts); + XFREE_CLEAR(lp->sl_kbyts); + XFREE_CLEAR(lp->sl_pbyts); + + XFREE_CLEAR(lp->sl_fidxs); + XFREE_CLEAR(lp->sl_kidxs); + XFREE_CLEAR(lp->sl_pidxs); GA_DEEP_CLEAR(&lp->sl_rep, fromto_T, free_fromto); GA_DEEP_CLEAR(&lp->sl_repsal, fromto_T, free_fromto); @@ -1738,26 +1732,17 @@ void slang_clear(slang_T *lp) vim_regfree(lp->sl_prefprog[i]); } lp->sl_prefixcnt = 0; - xfree(lp->sl_prefprog); - lp->sl_prefprog = NULL; - - xfree(lp->sl_info); - lp->sl_info = NULL; - - xfree(lp->sl_midword); - lp->sl_midword = NULL; + XFREE_CLEAR(lp->sl_prefprog); + XFREE_CLEAR(lp->sl_info); + XFREE_CLEAR(lp->sl_midword); vim_regfree(lp->sl_compprog); - xfree(lp->sl_comprules); - xfree(lp->sl_compstartflags); - xfree(lp->sl_compallflags); lp->sl_compprog = NULL; - lp->sl_comprules = NULL; - lp->sl_compstartflags = NULL; - lp->sl_compallflags = NULL; + XFREE_CLEAR(lp->sl_comprules); + XFREE_CLEAR(lp->sl_compstartflags); + XFREE_CLEAR(lp->sl_compallflags); - xfree(lp->sl_syllable); - lp->sl_syllable = NULL; + XFREE_CLEAR(lp->sl_syllable); ga_clear(&lp->sl_syl_items); ga_clear_strings(&lp->sl_comppat); @@ -1779,10 +1764,8 @@ void slang_clear(slang_T *lp) // Clear the info from the .sug file in "lp". void slang_clear_sug(slang_T *lp) { - xfree(lp->sl_sbyts); - lp->sl_sbyts = NULL; - xfree(lp->sl_sidxs); - lp->sl_sidxs = NULL; + XFREE_CLEAR(lp->sl_sbyts); + XFREE_CLEAR(lp->sl_sidxs); close_spellbuf(lp->sl_sugbuf); lp->sl_sugbuf = NULL; lp->sl_sugloaded = false; @@ -2255,8 +2238,7 @@ theend: static void clear_midword(win_T *wp) { memset(wp->w_s->b_spell_ismw, 0, 256); - xfree(wp->w_s->b_spell_ismw_mb); - wp->w_s->b_spell_ismw_mb = NULL; + XFREE_CLEAR(wp->w_s->b_spell_ismw_mb); } // Use the "sl_midword" field of language "lp" for buffer "buf". @@ -2415,8 +2397,7 @@ void spell_delete_wordlist(void) os_remove((char *)int_wordlist); int_wordlist_spl(fname); os_remove((char *)fname); - xfree(int_wordlist); - int_wordlist = NULL; + XFREE_CLEAR(int_wordlist); } } @@ -2438,10 +2419,8 @@ void spell_free_all(void) spell_delete_wordlist(); - xfree(repl_to); - repl_to = NULL; - xfree(repl_from); - repl_from = NULL; + XFREE_CLEAR(repl_to); + XFREE_CLEAR(repl_from); } // Clear all spelling tables and reload them. @@ -2838,10 +2817,8 @@ void spell_suggest(int count) smsg(_("Sorry, only %" PRId64 " suggestions"), (int64_t)sug.su_ga.ga_len); } else { - xfree(repl_from); - repl_from = NULL; - xfree(repl_to); - repl_to = NULL; + XFREE_CLEAR(repl_from); + XFREE_CLEAR(repl_to); // When 'rightleft' is set the list is drawn right-left. cmdmsg_rl = curwin->w_p_rl; diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 117939e7e9..5f5f74cf2e 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1446,8 +1446,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) // Copy flag to "sl_comprules", unless we run into a wildcard. if (crp != NULL) { if (c == '?' || c == '+' || c == '*') { - xfree(slang->sl_comprules); - slang->sl_comprules = NULL; + XFREE_CLEAR(slang->sl_comprules); crp = NULL; } else *crp++ = c; diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 1b30161e94..461316e63d 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -992,10 +992,10 @@ static void syn_stack_free_block(synblock_T *block) synstate_T *p; if (block->b_sst_array != NULL) { - for (p = block->b_sst_first; p != NULL; p = p->sst_next) + for (p = block->b_sst_first; p != NULL; p = p->sst_next) { clear_syn_state(p); - xfree(block->b_sst_array); - block->b_sst_array = NULL; + } + XFREE_CLEAR(block->b_sst_array); block->b_sst_len = 0; } } @@ -3186,8 +3186,7 @@ void syntax_clear(synblock_T *block) vim_regfree(block->b_syn_linecont_prog); block->b_syn_linecont_prog = NULL; - xfree(block->b_syn_linecont_pat); - block->b_syn_linecont_pat = NULL; + XFREE_CLEAR(block->b_syn_linecont_pat); block->b_syn_folditems = 0; clear_string_option(&block->b_syn_isk); @@ -3230,8 +3229,7 @@ static void syntax_sync_clear(void) vim_regfree(curwin->w_s->b_syn_linecont_prog); curwin->w_s->b_syn_linecont_prog = NULL; - xfree(curwin->w_s->b_syn_linecont_pat); - curwin->w_s->b_syn_linecont_pat = NULL; + XFREE_CLEAR(curwin->w_s->b_syn_linecont_pat); clear_string_option(&curwin->w_s->b_syn_isk); syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ @@ -3331,8 +3329,7 @@ static void syn_cmd_clear(exarg_T *eap, int syncing) // and make it empty. int scl_id = id - SYNID_CLUSTER; - xfree(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); - SYN_CLSTR(curwin->w_s)[scl_id].scl_list = NULL; + XFREE_CLEAR(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); } } else { id = syn_namen2id(arg, (int)(arg_end - arg)); @@ -5160,8 +5157,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) syn_clear_time(&curwin->w_s->b_syn_linecont_time); if (curwin->w_s->b_syn_linecont_prog == NULL) { - xfree(curwin->w_s->b_syn_linecont_pat); - curwin->w_s->b_syn_linecont_pat = NULL; + XFREE_CLEAR(curwin->w_s->b_syn_linecont_pat); finished = TRUE; break; } @@ -6993,12 +6989,9 @@ static void highlight_clear(int idx) HL_TABLE()[idx].sg_rgb_fg = -1; HL_TABLE()[idx].sg_rgb_bg = -1; HL_TABLE()[idx].sg_rgb_sp = -1; - xfree(HL_TABLE()[idx].sg_rgb_fg_name); - HL_TABLE()[idx].sg_rgb_fg_name = NULL; - xfree(HL_TABLE()[idx].sg_rgb_bg_name); - HL_TABLE()[idx].sg_rgb_bg_name = NULL; - xfree(HL_TABLE()[idx].sg_rgb_sp_name); - HL_TABLE()[idx].sg_rgb_sp_name = NULL; + XFREE_CLEAR(HL_TABLE()[idx].sg_rgb_fg_name); + XFREE_CLEAR(HL_TABLE()[idx].sg_rgb_bg_name); + XFREE_CLEAR(HL_TABLE()[idx].sg_rgb_sp_name); // Clear the script ID only when there is no link, since that is not // cleared. if (HL_TABLE()[idx].sg_link == 0) { diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 81af23f911..6e883a1c3d 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -923,8 +923,7 @@ end_do_tag: */ void tag_freematch(void) { - xfree(tagmatchname); - tagmatchname = NULL; + XFREE_CLEAR(tagmatchname); } static void taglen_advance(int l) @@ -1987,8 +1986,7 @@ void free_tag_stuff(void) tag_freematch(); if (ptag_entry.tagname) { - xfree(ptag_entry.tagname); - ptag_entry.tagname = NULL; + XFREE_CLEAR(ptag_entry.tagname); } } diff --git a/src/nvim/ugrid.c b/src/nvim/ugrid.c index f5bd35a48e..8adb421ee1 100644 --- a/src/nvim/ugrid.c +++ b/src/nvim/ugrid.c @@ -95,8 +95,7 @@ static void destroy_cells(UGrid *grid) for (int i = 0; i < grid->height; i++) { xfree(grid->cells[i]); } - xfree(grid->cells); - grid->cells = NULL; + XFREE_CLEAR(grid->cells); } } diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index e24ab11a3a..f6573e7488 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -92,10 +92,8 @@ void ui_comp_detach(UI *ui) { composed_uis--; if (composed_uis == 0) { - xfree(linebuf); - xfree(attrbuf); - linebuf = NULL; - attrbuf = NULL; + XFREE_CLEAR(linebuf); + XFREE_CLEAR(attrbuf); bufsize = 0; } ui->composed = false; diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 2cc3e928f7..8c90c4bf30 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -714,8 +714,7 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading) && (!reading || os_path_exists((char_u *)undo_file_name))) { break; } - xfree(undo_file_name); - undo_file_name = NULL; + XFREE_CLEAR(undo_file_name); } xfree(munged_name); @@ -2887,8 +2886,7 @@ void u_saveline(linenr_T lnum) void u_clearline(void) { if (curbuf->b_u_line_ptr != NULL) { - xfree(curbuf->b_u_line_ptr); - curbuf->b_u_line_ptr = NULL; + XFREE_CLEAR(curbuf->b_u_line_ptr); curbuf->b_u_line_lnum = 0; } } diff --git a/src/nvim/window.c b/src/nvim/window.c index 6bc082ffb2..3f555b9b2e 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -558,8 +558,7 @@ win_T *win_new_float(win_T *wp, FloatConfig fconfig, Error *err) } int dir; winframe_remove(wp, &dir, NULL); - xfree(wp->w_frame); - wp->w_frame = NULL; + XFREE_CLEAR(wp->w_frame); (void)win_comp_pos(); // recompute window positions win_remove(wp, NULL); win_append(lastwin_nofloating(), wp); @@ -4297,8 +4296,7 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid, do_autocmd_dirchanged((char *)globaldir, kCdScopeGlobal); } } - xfree(globaldir); - globaldir = NULL; + XFREE_CLEAR(globaldir); shorten_fnames(TRUE); } |