]> granicus.if.org Git - vim/commitdiff
patch 8.0.1496: clearing a pointer takes two lines v8.0.1496
authorBram Moolenaar <Bram@vim.org>
Sat, 10 Feb 2018 17:45:26 +0000 (18:45 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 10 Feb 2018 17:45:26 +0000 (18:45 +0100)
Problem:    Clearing a pointer takes two lines.
Solution:   Add VIM_CLEAR() and replace vim_clear(). (Hirohito Higashi,
            closes #2629)

54 files changed:
src/buffer.c
src/channel.c
src/crypt.c
src/edit.c
src/eval.c
src/evalfunc.c
src/ex_cmds.c
src/ex_cmds2.c
src/ex_docmd.c
src/ex_getln.c
src/fileio.c
src/gui_gtk_x11.c
src/gui_photon.c
src/gui_w32.c
src/gui_x11.c
src/hardcopy.c
src/if_cscope.c
src/macros.h
src/main.c
src/mark.c
src/mbyte.c
src/memfile.c
src/memline.c
src/menu.c
src/message.c
src/misc1.c
src/misc2.c
src/netbeans.c
src/normal.c
src/ops.c
src/option.c
src/os_amiga.c
src/os_mac_conv.c
src/os_mswin.c
src/os_unix.c
src/os_win32.c
src/popupmnu.c
src/proto/misc2.pro
src/quickfix.c
src/regexp.c
src/regexp_nfa.c
src/screen.c
src/search.c
src/spell.c
src/spellfile.c
src/syntax.c
src/tag.c
src/term.c
src/terminal.c
src/ui.c
src/undo.c
src/userfunc.c
src/version.c
src/window.c

index c0d3d3d9fc4122eedb129a8339f91b9166c60edc..c3e0c50801d0e353eff050c720735a2f62724b7a 100644 (file)
@@ -944,8 +944,7 @@ free_buffer_stuff(
     map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE);   /* clear local abbrevs */
 #endif
 #ifdef FEAT_MBYTE
-    vim_free(buf->b_start_fenc);
-    buf->b_start_fenc = NULL;
+    VIM_CLEAR(buf->b_start_fenc);
 #endif
 }
 
@@ -2037,10 +2036,8 @@ buflist_new(
     if ((ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL))
            || buf->b_wininfo == NULL)
     {
-       vim_free(buf->b_ffname);
-       buf->b_ffname = NULL;
-       vim_free(buf->b_sfname);
-       buf->b_sfname = NULL;
+       VIM_CLEAR(buf->b_ffname);
+       VIM_CLEAR(buf->b_sfname);
        if (buf != curbuf)
            free_buffer(buf);
        return NULL;
@@ -3136,10 +3133,8 @@ setfname(
     if (ffname == NULL || *ffname == NUL)
     {
        /* Removing the name. */
-       vim_free(buf->b_ffname);
-       vim_free(buf->b_sfname);
-       buf->b_ffname = NULL;
-       buf->b_sfname = NULL;
+       VIM_CLEAR(buf->b_ffname);
+       VIM_CLEAR(buf->b_sfname);
 #ifdef UNIX
        st.st_dev = (dev_T)-1;
 #endif
@@ -4261,8 +4256,7 @@ build_stl_str_hl(
                if (*skipdigits(str) == NUL)
                {
                    num = atoi((char *)str);
-                   vim_free(str);
-                   str = NULL;
+                   VIM_CLEAR(str);
                    itemisflag = FALSE;
                }
            }
index 138b12eceb6009aa1b20927fb0f719a205880a4a..77df42dd9250efab245a511a2429718c9c61c028 100644 (file)
@@ -317,8 +317,8 @@ channel_still_useful(channel_T *channel)
     /* If there is no callback then nobody can get readahead.  If the fd is
      * closed and there is no readahead then the callback won't be called. */
     has_sock_msg = channel->ch_part[PART_SOCK].ch_fd != INVALID_FD
-                 || channel->ch_part[PART_SOCK].ch_head.rq_next != NULL
-                 || channel->ch_part[PART_SOCK].ch_json_head.jq_next != NULL;
+               || channel->ch_part[PART_SOCK].ch_head.rq_next != NULL
+               || channel->ch_part[PART_SOCK].ch_json_head.jq_next != NULL;
     has_out_msg = channel->ch_part[PART_OUT].ch_fd != INVALID_FD
                  || channel->ch_part[PART_OUT].ch_head.rq_next != NULL
                  || channel->ch_part[PART_OUT].ch_json_head.jq_next != NULL;
@@ -2978,8 +2978,7 @@ channel_clear_one(channel_T *channel, ch_part_T part)
 channel_clear(channel_T *channel)
 {
     ch_log(channel, "Clearing channel");
-    vim_free(channel->ch_hostname);
-    channel->ch_hostname = NULL;
+    VIM_CLEAR(channel->ch_hostname);
     channel_clear_one(channel, PART_SOCK);
     channel_clear_one(channel, PART_OUT);
     channel_clear_one(channel, PART_ERR);
index 81759069f7b869b0865b5168ca01d83b552bc0c9..dfbf02ca5f443d852daf216ca44cab354c26372c 100644 (file)
@@ -118,6 +118,9 @@ static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = {
        NULL, NULL,
        crypt_blowfish_encode, crypt_blowfish_decode,
     },
+
+    /* NOTE: when adding a new method, use some random bytes for the magic key,
+     * to avoid that a text file is recognized as encrypted. */
 };
 
 #define CRYPT_MAGIC_LEN        12      /* cannot change */
@@ -349,10 +352,7 @@ crypt_create_for_writing(
 
     state = crypt_create(method_nr, key, salt, salt_len, seed, seed_len);
     if (state == NULL)
-    {
-       vim_free(*header);
-       *header = NULL;
-    }
+       VIM_CLEAR(*header);
     return state;
 }
 
index 7074f264869cf96cbed5fb89a9ad8b4bac95697d..f0e5c5185c4a8534d0f3710b989bdc53d9b934a9 100644 (file)
@@ -2939,7 +2939,7 @@ ins_compl_del_pum(void)
     if (compl_match_array != NULL)
     {
        pum_undisplay();
-       vim_clear((void **)&compl_match_array);
+       VIM_CLEAR(compl_match_array);
     }
 }
 
@@ -3441,8 +3441,8 @@ ins_compl_free(void)
     compl_T *match;
     int            i;
 
-    vim_clear((void **)&compl_pattern);
-    vim_clear((void **)&compl_leader);
+    VIM_CLEAR(compl_pattern);
+    VIM_CLEAR(compl_leader);
 
     if (compl_first_match == NULL)
        return;
@@ -3474,10 +3474,10 @@ ins_compl_clear(void)
     compl_cont_status = 0;
     compl_started = FALSE;
     compl_matches = 0;
-    vim_clear((void **)&compl_pattern);
-    vim_clear((void **)&compl_leader);
+    VIM_CLEAR(compl_pattern);
+    VIM_CLEAR(compl_leader);
     edit_submode_extra = NULL;
-    vim_clear((void **)&compl_orig_text);
+    VIM_CLEAR(compl_orig_text);
     compl_enter_selects = FALSE;
     /* clear v:completed_item */
     set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc_lock(VAR_FIXED));
@@ -5584,8 +5584,8 @@ ins_complete(int c, int enable_pum)
        if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
                        -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
        {
-           vim_clear((void **)&compl_pattern);
-           vim_clear((void **)&compl_orig_text);
+           VIM_CLEAR(compl_pattern);
+           VIM_CLEAR(compl_orig_text);
            return FAIL;
        }
 
@@ -7214,9 +7214,9 @@ set_last_insert(int c)
     void
 free_last_insert(void)
 {
-    vim_clear((void **)&last_insert);
+    VIM_CLEAR(last_insert);
 # ifdef FEAT_INS_EXPAND
-    vim_clear((void **)&compl_orig_text);
+    VIM_CLEAR(compl_orig_text);
 # endif
 }
 #endif
@@ -7844,7 +7844,7 @@ mb_replace_pop_ins(int cc)
     static void
 replace_flush(void)
 {
-    vim_clear((void **)&replace_stack);
+    VIM_CLEAR(replace_stack);
     replace_stack_len = 0;
     replace_stack_nr = 0;
 }
index 85f607cb77890e2597243fcc019e7ecb3596a151..f20fdda13539bb2927d5fa02baa3019732ca5338 100644 (file)
@@ -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_CLEAR(redir_ga.ga_data);
 
-       vim_free(redir_lval);
-       redir_lval = NULL;
+       VIM_CLEAR(redir_lval);
     }
-    vim_free(redir_varname);
-    redir_varname = NULL;
+    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, int evaluate)
            /* 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);
index 4b34538b7b1910da70ba2c38d4fdd527cf39da7c..f09be92af4dfcbdce7e3bec34533198b146a538f 100644 (file)
@@ -9222,10 +9222,7 @@ f_resolve(typval_T *argvars, typval_T *rettv)
            if (*q != NUL)
                STRMOVE(remain, q - 1);
            else
-           {
-               vim_free(remain);
-               remain = NULL;
-           }
+               VIM_CLEAR(remain);
        }
 
        /* If the result is a relative path name, make it explicitly relative to
index f4129019ab2d32c673bb20f999215db27d7e280e..11dac062024e26e146792cf6d3b5613813c7c1ea 100644 (file)
@@ -1957,8 +1957,7 @@ write_viminfo(char_u *file, int forceit)
                    if (!shortname && st_new.st_dev == st_old.st_dev
                                                && st_new.st_ino == st_old.st_ino)
                    {
-                       vim_free(tempname);
-                       tempname = NULL;
+                       VIM_CLEAR(tempname);
                        shortname = TRUE;
                        break;
                    }
@@ -5225,8 +5224,7 @@ do_sub(exarg_T *eap)
                    lnum += regmatch.startpos[0].lnum;
                    sub_firstlnum += regmatch.startpos[0].lnum;
                    nmatch -= regmatch.startpos[0].lnum;
-                   vim_free(sub_firstline);
-                   sub_firstline = NULL;
+                   VIM_CLEAR(sub_firstline);
                }
 
                if (sub_firstline == NULL)
@@ -5388,10 +5386,7 @@ do_sub(exarg_T *eap)
                                                     sub_firstline + copycol);
 
                                    if (new_line == NULL)
-                                   {
-                                       vim_free(orig_line);
-                                       orig_line = NULL;
-                                   }
+                                       VIM_CLEAR(orig_line);
                                    else
                                    {
                                        /* Position the cursor relative to the
@@ -5820,8 +5815,7 @@ skip:
            if (did_sub)
                ++sub_nlines;
            vim_free(new_start);        /* for when substitute was cancelled */
-           vim_free(sub_firstline);    /* free the copy of the original line */
-           sub_firstline = NULL;
+           VIM_CLEAR(sub_firstline);   /* free the copy of the original line */
        }
 
        line_breakcheck();
@@ -6975,8 +6969,7 @@ fix_help_buffer(void)
                                    && fnamecmp(e1, fname + 4) != 0)
                                {
                                    /* Not .txt and not .abx, remove it. */
-                                   vim_free(fnames[i1]);
-                                   fnames[i1] = NULL;
+                                   VIM_CLEAR(fnames[i1]);
                                    continue;
                                }
                                if (e1 - f1 != e2 - f2
@@ -6984,11 +6977,8 @@ fix_help_buffer(void)
                                    continue;
                                if (fnamecmp(e1, ".txt") == 0
                                    && fnamecmp(e2, fname + 4) == 0)
-                               {
                                    /* use .abx instead of .txt */
-                                   vim_free(fnames[i1]);
-                                   fnames[i1] = NULL;
-                               }
+                                   VIM_CLEAR(fnames[i1]);
                            }
                        }
 #endif
index 73fe0194beb00d7963e9c89e1a138ab16085c436..6caed87bb29a40c3edb189e9139e8ec5056f45fa 100644 (file)
@@ -1298,7 +1298,6 @@ check_due_timer(void)
        if (this_due <= 1)
        {
            bevalexpr_due_set = FALSE;
-
            if (balloonEval == NULL)
            {
                balloonEval = (BalloonEval *)alloc(sizeof(BalloonEval));
@@ -5489,8 +5488,7 @@ free_locales(void)
     {
        for (i = 0; locales[i] != NULL; i++)
            vim_free(locales[i]);
-       vim_free(locales);
-       locales = NULL;
+       VIM_CLEAR(locales);
     }
 }
 #  endif
index 591775f4c4c2efaef63c7731873396522e964496..4082636767984232d32587e5fa3847b5e6a24e47 100644 (file)
@@ -868,8 +868,7 @@ do_cmdline(
        {
            /* Each '|' separated command is stored separately in lines_ga, to
             * be able to jump to it.  Don't use next_cmdline now. */
-           vim_free(cmdline_copy);
-           cmdline_copy = NULL;
+           VIM_CLEAR(cmdline_copy);
 
            /* Check if a function has returned or, unless it has an unclosed
             * try conditional, aborted. */
@@ -1084,8 +1083,7 @@ do_cmdline(
 
        if (next_cmdline == NULL)
        {
-           vim_free(cmdline_copy);
-           cmdline_copy = NULL;
+           VIM_CLEAR(cmdline_copy);
 #ifdef FEAT_CMDHIST
            /*
             * If the command was typed, remember it for the ':' register.
@@ -5802,11 +5800,9 @@ uc_add_command(
                goto fail;
            }
 
-           vim_free(cmd->uc_rep);
-           cmd->uc_rep = NULL;
+           VIM_CLEAR(cmd->uc_rep);
 #if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
-           vim_free(cmd->uc_compl_arg);
-           cmd->uc_compl_arg = NULL;
+           VIM_CLEAR(cmd->uc_compl_arg);
 #endif
            break;
        }
@@ -8952,11 +8948,8 @@ static char_u    *prev_dir = NULL;
     void
 free_cd_dir(void)
 {
-    vim_free(prev_dir);
-    prev_dir = NULL;
-
-    vim_free(globaldir);
-    globaldir = NULL;
+    VIM_CLEAR(prev_dir);
+    VIM_CLEAR(globaldir);
 }
 #endif
 
@@ -8967,8 +8960,7 @@ free_cd_dir(void)
     void
 post_chdir(int local)
 {
-    vim_free(curwin->w_localdir);
-    curwin->w_localdir = NULL;
+    VIM_CLEAR(curwin->w_localdir);
     if (local)
     {
        /* If still in global directory, need to remember current
@@ -8983,8 +8975,7 @@ post_chdir(int local)
     {
        /* We are now in the global directory, no need to remember its
         * name. */
-       vim_free(globaldir);
-       globaldir = NULL;
+       VIM_CLEAR(globaldir);
     }
 
     shorten_fnames(TRUE);
index 837d29998fcff0bdee000c834a90243cd4a92b29..a9d6bd4833c24d8cf2a188553ae33351da84da0d 100644 (file)
@@ -164,8 +164,7 @@ trigger_cmd_autocmd(int typechar, int evt)
     static void
 abandon_cmdline(void)
 {
-    vim_free(ccline.cmdbuff);
-    ccline.cmdbuff = NULL;
+    VIM_CLEAR(ccline.cmdbuff);
     if (msg_scrolled == 0)
        compute_cmdrow();
     MSG("");
@@ -500,10 +499,7 @@ getcmdline(
                && c != K_KPAGEDOWN && c != K_KPAGEUP
                && c != K_LEFT && c != K_RIGHT
                && (xpc.xp_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N)))
-       {
-           vim_free(lookfor);
-           lookfor = NULL;
-       }
+           VIM_CLEAR(lookfor);
 #endif
 
        /*
@@ -1096,8 +1092,7 @@ getcmdline(
                            )
                        goto cmdline_not_changed;
 
-                   vim_free(ccline.cmdbuff);   /* no commandline to return */
-                   ccline.cmdbuff = NULL;
+                   VIM_CLEAR(ccline.cmdbuff);  /* no commandline to return */
                    if (!cmd_silent)
                    {
 #ifdef FEAT_RIGHTLEFT
@@ -3683,10 +3678,7 @@ nextwild(
                             || ccline.cmdbuff[i + j] == '?')
                         break;
                if ((int)STRLEN(p2) < j)
-               {
-                   vim_free(p2);
-                   p2 = NULL;
-               }
+                   VIM_CLEAR(p2);
            }
        }
     }
@@ -3832,8 +3824,7 @@ ExpandOne(
     {
        FreeWild(xp->xp_numfiles, xp->xp_files);
        xp->xp_numfiles = -1;
-       vim_free(orig_save);
-       orig_save = NULL;
+       VIM_CLEAR(orig_save);
     }
     findex = 0;
 
@@ -6737,8 +6728,7 @@ finish_viminfo_history(vir_T *virp)
        else
            concat_history(type);
 
-       vim_free(viminfo_history[type]);
-       viminfo_history[type] = NULL;
+       VIM_CLEAR(viminfo_history[type]);
        viminfo_hisidx[type] = 0;
     }
 }
@@ -6862,8 +6852,7 @@ write_viminfo_history(FILE *fp, int merge)
        for (i = 0; i < viminfo_hisidx[type]; ++i)
            if (viminfo_history[type] != NULL)
                vim_free(viminfo_history[type][i].hisstr);
-       vim_free(viminfo_history[type]);
-       viminfo_history[type] = NULL;
+       VIM_CLEAR(viminfo_history[type]);
        viminfo_hisidx[type] = 0;
     }
 }
index d4735f344e4cf44679d8dfdef2e48036f0c592b8..8798cff1b6c3a71478b0236c91c98f575b56ce3f 100644 (file)
@@ -1073,8 +1073,7 @@ retry:
        if (tmpname != NULL)
        {
            mch_remove(tmpname);                /* delete converted file */
-           vim_free(tmpname);
-           tmpname = NULL;
+           VIM_CLEAR(tmpname);
        }
     }
 
@@ -2602,8 +2601,7 @@ failed:
 #endif
                msg_add_lines(c, (long)linecnt, filesize);
 
-           vim_free(keep_msg);
-           keep_msg = NULL;
+           VIM_CLEAR(keep_msg);
            msg_scrolled_ign = TRUE;
 #ifdef ALWAYS_USE_GUI
            /* Don't show the message when reading stdin, it would end up in a
@@ -2955,8 +2953,7 @@ readfile_charconvert(
        if (tmpname != NULL)
        {
            mch_remove(tmpname);        /* delete converted file */
-           vim_free(tmpname);
-           tmpname = NULL;
+           VIM_CLEAR(tmpname);
        }
     }
 
@@ -3945,8 +3942,7 @@ buf_write(
                        if (st_new.st_dev == st_old.st_dev
                                            && st_new.st_ino == st_old.st_ino)
                        {
-                           vim_free(backup);
-                           backup = NULL;      /* no backup file to delete */
+                           VIM_CLEAR(backup);  /* no backup file to delete */
                            /*
                             * may try again with 'shortname' set
                             */
@@ -3980,10 +3976,7 @@ buf_write(
                                --*wp;
                            /* They all exist??? Must be something wrong. */
                            if (*wp == 'a')
-                           {
-                               vim_free(backup);
-                               backup = NULL;
-                           }
+                               VIM_CLEAR(backup);
                        }
                    }
                    break;
@@ -4010,10 +4003,7 @@ buf_write(
                    (void)umask(umask_save);
 #endif
                    if (bfd < 0)
-                   {
-                       vim_free(backup);
-                       backup = NULL;
-                   }
+                       VIM_CLEAR(backup);
                    else
                    {
                        /* Set file protection same as original file, but
@@ -4156,10 +4146,7 @@ buf_write(
                            --*p;
                        /* They all exist??? Must be something wrong! */
                        if (*p == 'a')
-                       {
-                           vim_free(backup);
-                           backup = NULL;
-                       }
+                           VIM_CLEAR(backup);
                    }
                }
                if (backup != NULL)
@@ -4177,8 +4164,7 @@ buf_write(
                    if (vim_rename(fname, backup) == 0)
                        break;
 
-                   vim_free(backup);   /* don't do the rename below */
-                   backup = NULL;
+                   VIM_CLEAR(backup);   /* don't do the rename below */
                }
            }
            if (backup == NULL && !forceit)
@@ -5079,8 +5065,7 @@ restore_backup:
            else if (mch_stat(org, &st) < 0)
            {
                vim_rename(backup, (char_u *)org);
-               vim_free(backup);           /* don't delete the file */
-               backup = NULL;
+               VIM_CLEAR(backup);          /* don't delete the file */
 #ifdef UNIX
                set_file_time((char_u *)org, st_old.st_atime, st_old.st_mtime);
 #endif
@@ -6227,8 +6212,7 @@ shorten_fnames(int force)
                    || buf->b_sfname == NULL
                    || mch_isFullName(buf->b_sfname)))
        {
-           vim_free(buf->b_sfname);
-           buf->b_sfname = NULL;
+           VIM_CLEAR(buf->b_sfname);
            p = shorten_fname(buf->b_ffname, dirname);
            if (p != NULL)
            {
@@ -7427,8 +7411,7 @@ vim_deltempdir(void)
        /* remove the trailing path separator */
        gettail(vim_tempdir)[-1] = NUL;
        delete_recursive(vim_tempdir);
-       vim_free(vim_tempdir);
-       vim_tempdir = NULL;
+       VIM_CLEAR(vim_tempdir);
     }
 }
 
@@ -8018,8 +8001,7 @@ show_autocmd(AutoPat *ap, event_T event)
     static void
 au_remove_pat(AutoPat *ap)
 {
-    vim_free(ap->pat);
-    ap->pat = NULL;
+    VIM_CLEAR(ap->pat);
     ap->buflocal_nr = -1;
     au_need_clean = TRUE;
 }
@@ -8033,10 +8015,7 @@ au_remove_cmds(AutoPat *ap)
     AutoCmd *ac;
 
     for (ac = ap->cmds; ac != NULL; ac = ac->next)
-    {
-       vim_free(ac->cmd);
-       ac->cmd = NULL;
-    }
+       VIM_CLEAR(ac->cmd);
     au_need_clean = TRUE;
 }
 
@@ -9094,8 +9073,7 @@ aucmd_prepbuf(
 
        /* Make sure w_localdir and globaldir are NULL to avoid a chdir() in
         * win_enter_ext(). */
-       vim_free(aucmd_win->w_localdir);
-       aucmd_win->w_localdir = NULL;
+       VIM_CLEAR(aucmd_win->w_localdir);
        aco->globaldir = globaldir;
        globaldir = NULL;
 
@@ -9877,8 +9855,7 @@ auto_next_pat(
     char_u     *name;
     char       *s;
 
-    vim_free(sourcing_name);
-    sourcing_name = NULL;
+    VIM_CLEAR(sourcing_name);
 
     for (ap = apc->curpat; ap != NULL && !got_int; ap = ap->next)
     {
@@ -10561,8 +10538,7 @@ file_pat_to_reg_pat(
            EMSG(_("E219: Missing {."));
        else
            EMSG(_("E220: Missing }."));
-       vim_free(reg_pat);
-       reg_pat = NULL;
+       VIM_CLEAR(reg_pat);
     }
     return reg_pat;
 }
index ad51be62c7277a73be56715c23a8d99a3689b0f7..2f88c2eeba397c7c97e00592db23c85cb7e1be82 100644 (file)
@@ -3838,8 +3838,7 @@ gui_mch_init(void)
 # endif
     }
 #endif
-    vim_free(gui_argv);
-    gui_argv = NULL;
+    VIM_CLEAR(gui_argv);
 
 #if GLIB_CHECK_VERSION(2,1,3)
     /* Set the human-readable application name */
@@ -4668,8 +4667,7 @@ gui_mch_open(void)
                y += hh - pixel_height;
            gtk_window_move(GTK_WINDOW(gui.mainwin), x, y);
        }
-       vim_free(gui.geom);
-       gui.geom = NULL;
+       VIM_CLEAR(gui.geom);
 
        /* From now until everyone's stopped trying to set the window hints
         * to their correct minimum values, stop them being set as we need
index fcfb4f6d9c7d9c8a3e089a89929049cee73b15d0..327b356514c2a5800986f82d32a8dedbdb74a1b5 100644 (file)
@@ -1040,8 +1040,7 @@ gui_ph_pg_remove_buffer(char *name)
        PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_PANEL_TITLES, &empty_title,
                1);
 
-       vim_free(panel_titles);
-       panel_titles = NULL;
+       VIM_CLEAR(panel_titles);
     }
 }
 
index 67aa1fc1144a570c41ba5f894bb88bc727e09c12..6596cf81e935662c2071e372cef59d8b3d7d090e 100644 (file)
@@ -4941,8 +4941,7 @@ _WndProc(
                    char_u              *str = NULL;
                    static void         *tt_text = NULL;
 
-                   vim_free(tt_text);
-                   tt_text = NULL;
+                   VIM_CLEAR(tt_text);
 
 # ifdef FEAT_GUI_TABLINE
                    if (gui_mch_showing_tabline()
index 34d584e78eabc6d50343c39f6b92772bc9c1dcb2..097de5f90e7eb6c9070db8870981fb7152c34664 100644 (file)
@@ -826,7 +826,7 @@ gui_x11_key_hit_cb(
 #  endif
                )
        {
-           int         maxlen = len * 4 + 40;  /* guessed */
+           int         maxlen = len * 4 + 40;  /* guessed */
            char_u      *p = (char_u *)XtMalloc(maxlen);
 
            mch_memmove(p, string, len);
@@ -1567,8 +1567,7 @@ gui_mch_uninit(void)
     XtCloseDisplay(gui.dpy);
     gui.dpy = NULL;
     vimShell = (Widget)0;
-    vim_free(gui_argv);
-    gui_argv = NULL;
+    VIM_CLEAR(gui_argv);
 }
 
 /*
@@ -1741,8 +1740,7 @@ gui_mch_exit(int rc UNUSED)
      * says that this isn't needed when exiting, so just skip it. */
     XtCloseDisplay(gui.dpy);
 #endif
-    vim_free(gui_argv);
-    gui_argv = NULL;
+    VIM_CLEAR(gui_argv);
 }
 
 /*
@@ -1956,7 +1954,7 @@ gui_mch_get_font(char_u *name, int giveErrorIfMissing)
 {
     XFontStruct        *font;
 
-    if (!gui.in_use || name == NULL)    /* can't do this when GUI not running */
+    if (!gui.in_use || name == NULL)   /* can't do this when GUI not running */
        return NOFONT;
 
     font = XLoadQueryFont(gui.dpy, (char *)name);
@@ -2275,7 +2273,7 @@ fontset_ascent(XFontSet fs)
     guicolor_T
 gui_mch_get_color(char_u *name)
 {
-    guicolor_T  requested;
+    guicolor_T requested;
 
     /* can't do this when GUI not running */
     if (!gui.in_use || name == NULL || *name == NUL)
@@ -2298,8 +2296,8 @@ gui_mch_get_color(char_u *name)
     guicolor_T
 gui_mch_get_rgb_color(int r, int g, int b)
 {
-    char        spec[8]; /* space enough to hold "#RRGGBB" */
-    XColor      available;
+    char       spec[8]; /* space enough to hold "#RRGGBB" */
+    XColor     available;
     Colormap   colormap;
 
     vim_snprintf(spec, sizeof(spec), "#%.2x%.2x%.2x", r, g, b);
index 4a0910d8c476b491de6a8046033eb4b745bde033..96fab2048a73ba1dc3d142bd89ac172cc3649e12 100644 (file)
@@ -2210,8 +2210,7 @@ mch_print_cleanup(void)
        for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++)
        {
            if (prt_ps_mb_font.ps_fontname[i] != NULL)
-               vim_free(prt_ps_mb_font.ps_fontname[i]);
-           prt_ps_mb_font.ps_fontname[i] = NULL;
+               VIM_CLEAR(prt_ps_mb_font.ps_fontname[i]);
        }
     }
 
@@ -2228,10 +2227,7 @@ mch_print_cleanup(void)
        prt_file_error = FALSE;
     }
     if (prt_ps_file_name != NULL)
-    {
-       vim_free(prt_ps_file_name);
-       prt_ps_file_name = NULL;
-    }
+       VIM_CLEAR(prt_ps_file_name);
 }
 
     static float
index 4bf28ad1d1c0c808f72a4d41cd505b05e4ee8831..e4bcb51e0071855b7a7b7033a502df972153a2f6 100644 (file)
@@ -1479,8 +1479,7 @@ cs_insert_filelist(
     {
        if ((csinfo[i].ppath = (char *)alloc((unsigned)strlen(ppath) + 1)) == NULL)
        {
-           vim_free(csinfo[i].fname);
-           csinfo[i].fname = NULL;
+           VIM_CLEAR(csinfo[i].fname);
            return -1;
        }
        (void)strcpy(csinfo[i].ppath, (const char *)ppath);
@@ -1491,10 +1490,8 @@ cs_insert_filelist(
     {
        if ((csinfo[i].flags = (char *)alloc((unsigned)strlen(flags) + 1)) == NULL)
        {
-           vim_free(csinfo[i].fname);
-           vim_free(csinfo[i].ppath);
-           csinfo[i].fname = NULL;
-           csinfo[i].ppath = NULL;
+           VIM_CLEAR(csinfo[i].fname);
+           VIM_CLEAR(csinfo[i].ppath);
            return -1;
        }
        (void)strcpy(csinfo[i].flags, (const char *)flags);
@@ -1939,10 +1936,8 @@ parse_out:
     if (totsofar == 0)
     {
        /* No matches, free the arrays and return NULL in "*matches_p". */
-       vim_free(matches);
-       matches = NULL;
-       vim_free(cntxts);
-       cntxts = NULL;
+       VIM_CLEAR(matches);
+       VIM_CLEAR(cntxts);
     }
     *matched = totsofar;
     *matches_p = matches;
@@ -2445,7 +2440,7 @@ cs_resolve_file(int i, char *name)
        if (csdir != NULL)
        {
            vim_strncpy(csdir, (char_u *)csinfo[i].fname,
-                                      gettail((char_u *)csinfo[i].fname)
+                                         gettail((char_u *)csinfo[i].fname)
                                                 - (char_u *)csinfo[i].fname);
            len += (int)STRLEN(csdir);
        }
index 6e4b813c0a715fe242d5accf1650e9849ab38a11..43d6c94cf05a3dcf89a5d64f4563b324b393e2c5 100644 (file)
 # define mch_enable_flush()
 # define mch_disable_flush()
 #endif
+
+/*
+ * Like vim_free(), and also set the pointer to NULL.
+ */
+#define VIM_CLEAR(p) \
+    do { \
+       if ((p) != NULL) { \
+           vim_free(p); \
+           (p) = NULL; \
+       } \
+    } while (0)
index 971590aab69e97d5b1bf77f1e7c6a1fecac270aa..78a30182e1faebf3dc22154e002c73abe170d2af 100644 (file)
@@ -3951,8 +3951,7 @@ cmdsrv_main(
                {
                    /* Output error from remote */
                    mch_errmsg((char *)res);
-                   vim_free(res);
-                   res = NULL;
+                   VIM_CLEAR(res);
                }
                mch_errmsg(_(": Send expression failed.\n"));
            }
index 342bfcd9f7ae874d81af460ff5ba0726b87aeb8a..1acdd12d65b97b5fde0b87a806d96b055a083f3b 100644 (file)
@@ -127,8 +127,7 @@ setmark_pos(int c, pos_T *pos, int fnum)
            i = c - 'A';
        namedfm[i].fmark.mark = *pos;
        namedfm[i].fmark.fnum = fnum;
-       vim_free(namedfm[i].fname);
-       namedfm[i].fname = NULL;
+       VIM_CLEAR(namedfm[i].fname);
 #ifdef FEAT_VIMINFO
        namedfm[i].time_set = vim_time();
 #endif
@@ -598,8 +597,7 @@ fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf)
            && fnamecmp(name, fm->fname) == 0)
     {
        fm->fmark.fnum = buf->b_fnum;
-       vim_free(fm->fname);
-       fm->fname = NULL;
+       VIM_CLEAR(fm->fname);
     }
 }
 
@@ -862,8 +860,7 @@ ex_delmarks(exarg_T *eap)
                        else
                            n = i - 'A';
                        namedfm[n].fmark.mark.lnum = 0;
-                       vim_free(namedfm[n].fname);
-                       namedfm[n].fname = NULL;
+                       VIM_CLEAR(namedfm[n].fname);
 #ifdef FEAT_VIMINFO
                        namedfm[n].time_set = 0;
 #endif
@@ -1480,16 +1477,14 @@ finish_viminfo_marks(void)
     {
        for (i = 0; i < NMARKS + EXTRA_MARKS; ++i)
            vim_free(vi_namedfm[i].fname);
-       vim_free(vi_namedfm);
-       vi_namedfm = NULL;
+       VIM_CLEAR(vi_namedfm);
     }
 #ifdef FEAT_JUMPLIST
     if (vi_jumplist != NULL)
     {
        for (i = 0; i < vi_jumplist_len; ++i)
            vim_free(vi_jumplist[i].fname);
-       vim_free(vi_jumplist);
-       vi_jumplist = NULL;
+       VIM_CLEAR(vi_jumplist);
     }
 #endif
 }
index 5ed321ed221306dc2c0c84069ee5d519ff117a80..575fd52d4a6aaa58883769b991c3fe08110e3cdb 100644 (file)
@@ -4666,8 +4666,7 @@ iconv_string(
        else if (ICONV_ERRNO != ICONV_E2BIG)
        {
            /* conversion failed */
-           vim_free(result);
-           result = NULL;
+           VIM_CLEAR(result);
            break;
        }
        /* Not enough room or skipping illegal sequence. */
index 0fb27871ba8b2b0e9a71bf7ccb006f035860c51b..0d07b7558633e6f189f7b313dfe9c47d2fd1521d 100644 (file)
@@ -297,10 +297,8 @@ mf_close_file(
     if (mfp->mf_fname != NULL)
     {
        mch_remove(mfp->mf_fname);              /* delete the swap file */
-       vim_free(mfp->mf_fname);
-       vim_free(mfp->mf_ffname);
-       mfp->mf_fname = NULL;
-       mfp->mf_ffname = NULL;
+       VIM_CLEAR(mfp->mf_fname);
+       VIM_CLEAR(mfp->mf_ffname);
     }
 }
 
@@ -1288,10 +1286,8 @@ mf_do_open(
      */
     if (mfp->mf_fd < 0)
     {
-       vim_free(mfp->mf_fname);
-       vim_free(mfp->mf_ffname);
-       mfp->mf_fname = NULL;
-       mfp->mf_ffname = NULL;
+       VIM_CLEAR(mfp->mf_fname);
+       VIM_CLEAR(mfp->mf_ffname);
     }
     else
     {
index 07721ee1a4e0d173d61b7e1122535ae7e11ecac2..7ea94ab8bd76d509d3499004c836517d3d15777c 100644 (file)
@@ -535,8 +535,7 @@ ml_set_crypt_key(
        idx = 0;                /* start with first index in block 1 */
        error = 0;
        buf->b_ml.ml_stack_top = 0;
-       vim_free(buf->b_ml.ml_stack);
-       buf->b_ml.ml_stack = NULL;
+       VIM_CLEAR(buf->b_ml.ml_stack);
        buf->b_ml.ml_stack_size = 0;    /* no stack yet */
 
        for ( ; !got_int; line_breakcheck())
@@ -852,8 +851,7 @@ ml_close(buf_T *buf, int del_file)
        vim_free(buf->b_ml.ml_line_ptr);
     vim_free(buf->b_ml.ml_stack);
 #ifdef FEAT_BYTEOFF
-    vim_free(buf->b_ml.ml_chunksize);
-    buf->b_ml.ml_chunksize = NULL;
+    VIM_CLEAR(buf->b_ml.ml_chunksize);
 #endif
     buf->b_ml.ml_mfp = NULL;
 
@@ -4197,8 +4195,7 @@ findswapname(
            break;
        if ((n = (int)STRLEN(fname)) == 0)      /* safety check */
        {
-           vim_free(fname);
-           fname = NULL;
+           VIM_CLEAR(fname);
            break;
        }
 #if defined(UNIX)
@@ -4578,8 +4575,7 @@ findswapname(
            if (fname[n - 2] == 'a')    /* ".saa": tried enough, give up */
            {
                EMSG(_("E326: Too many swap files found"));
-               vim_free(fname);
-               fname = NULL;
+               VIM_CLEAR(fname);
                break;
            }
            --fname[n - 2];             /* ".svz", ".suz", etc. */
index 3728aa779b289ff0c0052dfbe7040fdddc0f5ace..310cf5928f0e73e32e793d9873e7f9bf42f90bb1 100644 (file)
@@ -727,8 +727,7 @@ add_menu_path(
        menup = &menu->children;
        parent = menu;
        name = next_name;
-       vim_free(dname);
-       dname = NULL;
+       VIM_CLEAR(dname);
        if (pri_tab[pri_idx + 1] != -1)
            ++pri_idx;
     }
index 17a6633523611eb803f8f82f8b9d04999c17b4d7..71965852f20c6af52205096ff950c019f351b29d 100644 (file)
@@ -415,8 +415,7 @@ static char_u   *last_sourcing_name = NULL;
     void
 reset_last_sourcing(void)
 {
-    vim_free(last_sourcing_name);
-    last_sourcing_name = NULL;
+    VIM_CLEAR(last_sourcing_name);
     last_sourcing_lnum = 0;
 }
 
@@ -1249,10 +1248,7 @@ wait_return(int redraw)
     reset_last_sourcing();
     if (keep_msg != NULL && vim_strsize(keep_msg) >=
                                  (Rows - cmdline_row - 1) * Columns + sc_col)
-    {
-       vim_free(keep_msg);
-       keep_msg = NULL;            /* don't redisplay message, it's too long */
-    }
+       VIM_CLEAR(keep_msg);        /* don't redisplay message, it's too long */
 
     if (tmpState == SETWSIZE)      /* got resize event while in vgetc() */
     {
@@ -1325,10 +1321,7 @@ msg_start(void)
     int                did_return = FALSE;
 
     if (!msg_silent)
-    {
-       vim_free(keep_msg);
-       keep_msg = NULL;                /* don't display old message now */
-    }
+       VIM_CLEAR(keep_msg);
 
 #ifdef FEAT_EVAL
     if (need_clr_eos)
@@ -3481,8 +3474,7 @@ give_warning(char_u *message, int hl)
 #ifdef FEAT_EVAL
     set_vim_var_string(VV_WARNINGMSG, message, -1);
 #endif
-    vim_free(keep_msg);
-    keep_msg = NULL;
+    VIM_CLEAR(keep_msg);
     if (hl)
        keep_msg_attr = HL_ATTR(HLF_W);
     else
index 593dce1c3d14a553197907fd55107dc7352f3ada..821869aa3255521117a195e3af8c3907b3924b52 100644 (file)
@@ -3745,8 +3745,7 @@ init_homedir(void)
     char_u  *var;
 
     /* In case we are called a second time (when 'encoding' changes). */
-    vim_free(homedir);
-    homedir = NULL;
+    VIM_CLEAR(homedir);
 
 #ifdef VMS
     var = mch_getenv((char_u *)"SYS$LOGIN");
@@ -4358,10 +4357,7 @@ vim_getenv(char_u *name, int *mustfree)
                p = vim_strnsave(p, (int)(pend - p));
 
            if (p != NULL && !mch_isdir(p))
-           {
-               vim_free(p);
-               p = NULL;
-           }
+               VIM_CLEAR(p);
            else
            {
 #ifdef USE_EXE_NAME
@@ -9775,8 +9771,7 @@ expand_wildcards(
        /* If the number of matches is now zero, we fail. */
        if (*num_files == 0)
        {
-           vim_free(*files);
-           *files = NULL;
+           VIM_CLEAR(*files);
            return FAIL;
        }
     }
@@ -10031,10 +10026,7 @@ dos_expandpath(
            hFind = FindFirstFileW(wn, &wfb);
            if (hFind == INVALID_HANDLE_VALUE
                              && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
-           {
-               vim_free(wn);
-               wn = NULL;
-           }
+               VIM_CLEAR(wn);
        }
     }
 
@@ -10122,8 +10114,7 @@ dos_expandpath(
 # endif
                hFind = FindFirstFile((LPCSTR)buf, &fb);
            ok = (hFind != INVALID_HANDLE_VALUE);
-           vim_free(matchname);
-           matchname = NULL;
+           VIM_CLEAR(matchname);
        }
     }
 
@@ -11256,8 +11247,7 @@ get_cmd_output(
     if (i != len)
     {
        EMSG2(_(e_notread), tempname);
-       vim_free(buffer);
-       buffer = NULL;
+       VIM_CLEAR(buffer);
     }
     else if (ret_len == NULL)
     {
index 0deccdf509d375096f8894febaf848b603c380cf..1c705932dcc4d72ef1b29c1ff9a5c49a7b393d44 100644 (file)
@@ -1827,6 +1827,8 @@ copy_option_part(
  * Replacement for free() that ignores NULL pointers.
  * Also skip free() when exiting for sure, this helps when we caught a deadly
  * signal that was caused by a crash in free().
+ * If you want to set NULL after calling this function, you should use
+ * VIM_CLEAR() instead.
  */
     void
 vim_free(void *x)
@@ -1840,19 +1842,6 @@ vim_free(void *x)
     }
 }
 
-/*
- * Like vim_free(), and also set the pointer to NULL.
- */
-    void
-vim_clear(void **x)
-{
-    if (*x != NULL)
-    {
-       vim_free(*x);
-       *x = NULL;
-    }
-}
-
 #ifndef HAVE_MEMSET
     void *
 vim_memset(void *ptr, int c, size_t size)
index 199cfd63cd817036f7b6089167f731a2e917cc4e..bc3b8e680b7d335102fbdfea781284d435c14533 100644 (file)
@@ -580,8 +580,7 @@ nb_free(void)
            buf.bufp->b_was_netbeans_file = FALSE;
        }
     }
-    vim_free(buf_list);
-    buf_list = NULL;
+    VIM_CLEAR(buf_list);
     buf_list_size = 0;
     buf_list_used = 0;
 
@@ -1477,8 +1476,7 @@ nb_do_cmd(
                EMSG("E636: invalid buffer identifier in create");
                return FAIL;
            }
-           vim_free(buf->displayname);
-           buf->displayname = NULL;
+           VIM_CLEAR(buf->displayname);
 
            netbeansReadFile = 0; /* don't try to open disk file */
            do_ecmd(0, NULL, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF, curwin);
@@ -3447,8 +3445,7 @@ print_read_msg(nbbuf_T *buf)
     msg_add_lines(c, (long)lnum, nchars);
 
     /* Now display it */
-    vim_free(keep_msg);
-    keep_msg = NULL;
+    VIM_CLEAR(keep_msg);
     msg_scrolled_ign = TRUE;
     msg_trunc_attr(IObuff, FALSE, 0);
     msg_scrolled_ign = FALSE;
@@ -3475,8 +3472,7 @@ print_save_msg(nbbuf_T *buf, off_T nchars)
        msg_add_lines(c, buf->bufp->b_ml.ml_line_count,
                                                buf->bufp->b_orig_size);
 
-       vim_free(keep_msg);
-       keep_msg = NULL;
+       VIM_CLEAR(keep_msg);
        msg_scrolled_ign = TRUE;
        p = msg_trunc_attr(IObuff, FALSE, 0);
        if ((msg_scrolled && !need_wait_return) || !buf->initDone)
index 79e0b68aa8f8f407a2ea37dce4115de720337238..31ec36306ebc882b614e8a6ec5177f53c1cbab38 100644 (file)
@@ -1482,8 +1482,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
                {
                    AppendToRedobuffLit(repeat_cmdline, -1);
                    AppendToRedobuff(NL_STR);
-                   vim_free(repeat_cmdline);
-                   repeat_cmdline = NULL;
+                   VIM_CLEAR(repeat_cmdline);
                }
            }
        }
index 1350d826413e788d2af115e241591148de9839c4..830de0ba6d7883223c6ca2793f50a53a810d304b 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -1235,8 +1235,7 @@ do_execreg(
            EMSG(_(e_nolastcmd));
            return FAIL;
        }
-       vim_free(new_last_cmdline); /* don't keep the cmdline containing @: */
-       new_last_cmdline = NULL;
+       VIM_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 *)"\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", Ctrl_V, FALSE);
@@ -2995,8 +2994,7 @@ free_yank(long n)
 #endif
            vim_free(y_current->y_array[i]);
        }
-       vim_free(y_current->y_array);
-       y_current->y_array = NULL;
+       VIM_CLEAR(y_current->y_array);
 #ifdef AMIGA
        if (n >= 1000)
            MSG("");
@@ -6040,8 +6038,7 @@ finish_viminfo_registers(void)
                    vim_free(y_read_regs[i].y_array[j]);
                vim_free(y_read_regs[i].y_array);
            }
-       vim_free(y_read_regs);
-       y_read_regs = NULL;
+       VIM_CLEAR(y_read_regs);
     }
 }
 
@@ -7146,8 +7143,7 @@ str_to_reg(
     /* Without any lines make the register empty. */
     if (y_ptr->y_size + newlines == 0)
     {
-       vim_free(y_ptr->y_array);
-       y_ptr->y_array = NULL;
+       VIM_CLEAR(y_ptr->y_array);
        return;
     }
 
index e54ba4e2de118294ee42c451c88c38f2abb7ad2f..21ca0fa48bc90d399d51248a2bdcafbcf54218a5 100644 (file)
@@ -11735,8 +11735,7 @@ ExpandOldSetting(int *num_file, char_u ***file)
 
     if (buf == NULL)
     {
-       vim_free(*file);
-       *file = NULL;
+       VIM_CLEAR(*file);
        return FAIL;
     }
 
index 85e0c4ef0e9344cf61bd98cde106a1b6594daf98..a0fb5c0841b2be3c5d3cae4fe536a35a58527dcc 100644 (file)
@@ -1619,8 +1619,7 @@ mch_getenv(char_u *var)
     else
 #endif
     {
-       vim_free(alloced);
-       alloced = NULL;
+       VIM_CLEAR(alloced);
        retval = NULL;
 
        buf = alloc(IOSIZE);
index 1fddc61f33ea19aab87c002736e1dc3a053a59ed..2bd337ea6f8ab63d1cfd0dbe1f78957f30cb6652 100644 (file)
@@ -480,10 +480,7 @@ mac_precompose_path(
            if (TECConvertText(gPathConverter, decompPath,
                        decompLen, &decompLen, result,
                        decompLen, &actualLen) != noErr)
-           {
-               vim_free(result);
-               result = NULL;
-           }
+               VIM_CLEAR(result);
        }
     }
 
@@ -517,10 +514,7 @@ mac_utf16_to_utf8(
            utf8_len += inputRead;
        }
        else
-       {
-           vim_free(result);
-           result = NULL;
-       }
+           VIM_CLEAR(result);
     }
     else
     {
index ef756421fc755f239d4cfa670234611d4a81eeaf..a41b4c82bcd42ccdcd2c683f284aaebd9e3f3be1 100644 (file)
@@ -1233,8 +1233,7 @@ PrintDlgProc(
            if (prt_name != NULL)
            {
                vimSetDlgItemText(hDlg, IDC_PRINTTEXT2, (char_u *)prt_name);
-               vim_free(prt_name);
-               prt_name = NULL;
+               VIM_CLEAR(prt_name);
            }
            EnableMenuItem(GetSystemMenu(hDlg, FALSE), SC_CLOSE, MF_GRAYED);
 #ifndef FEAT_GUI
@@ -2608,6 +2607,7 @@ serverGetReply(HWND server, int *expr_res, int remove, int wait, int timeout)
        while (reply_received == 0)
        {
 #ifdef FEAT_TIMERS
+           /* TODO: use the return value to decide how long to wait. */
            check_due_timer();
 #endif
            time(&now);
index ff0b0e88d61940fdb670b439ece8c8197082ed0f..3788da99180ebbde3fd09e752dcbcf71cf72d02b 100644 (file)
@@ -371,7 +371,7 @@ mch_chdir(char *path)
 #endif
 
 /*
- * Write s[len] to the screen.
+ * Write s[len] to the screen (stdout).
  */
     void
 mch_write(char_u *s, int len)
@@ -1311,8 +1311,7 @@ mch_suspend(void)
     /*
      * Set oldtitle to NULL, so the current title is obtained again.
      */
-    vim_free(oldtitle);
-    oldtitle = NULL;
+    VIM_CLEAR(oldtitle);
 # endif
     settmode(TMODE_RAW);
     need_check_timestamps = TRUE;
@@ -3261,8 +3260,7 @@ mch_free_mem(void)
        XCloseDisplay(x11_display);
 # endif
 # if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK)
-    vim_free(signal_stack);
-    signal_stack = NULL;
+    VIM_CLEAR(signal_stack);
 # endif
 # ifdef FEAT_TITLE
     vim_free(oldtitle);
@@ -6765,8 +6763,7 @@ mch_expand_wildcards(
 
     if (*num_file == 0)            /* rejected all entries */
     {
-       vim_free(*file);
-       *file = NULL;
+       VIM_CLEAR(*file);
        goto notfound;
     }
 
index a42df6f29f14a45347f74a57942a74c7f2aa33b5..121ff2aa1b80571f6c107945b2b707ef6e0ff396 100644 (file)
@@ -2252,8 +2252,7 @@ SaveConsoleBuffer(
        cb->Regions = (PSMALL_RECT)alloc(cb->NumRegions * sizeof(SMALL_RECT));
        if (cb->Regions == NULL)
        {
-           vim_free(cb->Buffer);
-           cb->Buffer = NULL;
+           VIM_CLEAR(cb->Buffer);
            return FALSE;
        }
     }
@@ -2278,10 +2277,8 @@ SaveConsoleBuffer(
                BufferCoord,                    /* offset in our buffer */
                &ReadRegion))                   /* region to save */
        {
-           vim_free(cb->Buffer);
-           cb->Buffer = NULL;
-           vim_free(cb->Regions);
-           cb->Regions = NULL;
+           VIM_CLEAR(cb->Buffer);
+           VIM_CLEAR(cb->Regions);
            return FALSE;
        }
        cb->Regions[i] = ReadRegion;
index 09d9520a638ed890dd15cf276c4a00e26f4fda2b..2839ea1997f96015fcba84a1695e35ff318391c2 100644 (file)
@@ -975,8 +975,7 @@ ui_remove_balloon(void)
        pum_undisplay();
        while (balloon_arraysize > 0)
            vim_free(balloon_array[--balloon_arraysize].pum_text);
-       vim_free(balloon_array);
-       balloon_array = NULL;
+       VIM_CLEAR(balloon_array);
     }
 }
 
index 4c20a7c0f0c7d2eed862c5eb6747daf937e0f9b4..6999683c7bdbe6ede047ac8f39c036c728bee278 100644 (file)
@@ -46,7 +46,6 @@ void vim_strncpy(char_u *to, char_u *from, size_t len);
 void vim_strcat(char_u *to, char_u *from, size_t tosize);
 int copy_option_part(char_u **option, char_u *buf, int maxlen, char *sep_chars);
 void vim_free(void *x);
-void vim_clear(void **x);
 int vim_stricmp(char *s1, char *s2);
 int vim_strnicmp(char *s1, char *s2, size_t len);
 char_u *vim_strchr(char_u *string, int c);
index b2dabaaacd0d48f4b14b95d0420451d03af64dc8..c3b28e4ec3244d65f0570e63f952b3d3f560e14a 100644 (file)
@@ -1177,8 +1177,7 @@ qf_init_ext(
     int                    status;
 
     /* Do not used the cached buffer, it may have been wiped out. */
-    vim_free(qf_last_bufname);
-    qf_last_bufname = NULL;
+    VIM_CLEAR(qf_last_bufname);
 
     vim_memset(&state, 0, sizeof(state));
     vim_memset(&fields, 0, sizeof(fields));
@@ -1229,8 +1228,7 @@ qf_init_ext(
     if (last_efm == NULL || (STRCMP(last_efm, efm) != 0))
     {
        /* free the previously parsed data */
-       vim_free(last_efm);
-       last_efm = NULL;
+       VIM_CLEAR(last_efm);
        free_efm_list(&fmt_first);
 
        /* parse the current 'efm' */
@@ -1351,8 +1349,7 @@ qf_init_end:
     static void
 qf_store_title(qf_info_T *qi, int qf_idx, char_u *title)
 {
-    vim_free(qi->qf_lists[qf_idx].qf_title);
-    qi->qf_lists[qf_idx].qf_title = NULL;
+    VIM_CLEAR(qi->qf_lists[qf_idx].qf_title);
 
     if (title != NULL)
     {
@@ -3003,8 +3000,7 @@ qf_free(qf_info_T *qi, int idx)
 
     qf_free_items(qi, idx);
 
-    vim_free(qfl->qf_title);
-    qfl->qf_title = NULL;
+    VIM_CLEAR(qfl->qf_title);
     free_tv(qfl->qf_ctx);
     qfl->qf_ctx = NULL;
     qfl->qf_id = 0;
index 7f5e265eb868478a8bda79ad66fb28456312fa9d..d07391eefb93984ff88a15638a1948c195766e5a 100644 (file)
@@ -3996,10 +3996,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)
-    {
-       vim_free(reg_tofree);
-       reg_tofree = NULL;
-    }
+       VIM_CLEAR(reg_tofree);
     if (regstack.ga_maxlen > REGSTACK_INITIAL)
        ga_clear(&regstack);
     if (backpos.ga_maxlen > BACKPOS_INITIAL)
@@ -7521,8 +7518,7 @@ vim_regsub_both(
            {
                STRCPY(dest, eval_result);
                dst += STRLEN(eval_result);
-               vim_free(eval_result);
-               eval_result = NULL;
+               VIM_CLEAR(eval_result);
            }
        }
        else
@@ -8150,7 +8146,7 @@ vim_regcomp(char_u *expr_arg, int re_flags)
      * First try the NFA engine, unless backtracking was requested.
      */
     if (regexp_engine != BACKTRACKING_ENGINE)
-        prog = nfa_regengine.regcomp(expr,
+       prog = nfa_regengine.regcomp(expr,
                re_flags + (regexp_engine == AUTOMATIC_ENGINE ? RE_AUTO : 0));
     else
        prog = bt_regengine.regcomp(expr, re_flags);
@@ -8170,7 +8166,7 @@ vim_regcomp(char_u *expr_arg, int re_flags)
            }
            else
                EMSG2("(NFA) Could not open \"%s\" to write !!!",
-                        BT_REGEXP_DEBUG_LOG_NAME);
+                       BT_REGEXP_DEBUG_LOG_NAME);
        }
 #endif
        /*
@@ -8341,10 +8337,10 @@ vim_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col)
     long
 vim_regexec_multi(
     regmmatch_T *rmp,
-    win_T       *win,           /* window in which to search or NULL */
-    buf_T       *buf,           /* buffer in which to search */
-    linenr_T    lnum,           /* nr of line to start looking for match */
-    colnr_T     col,            /* column to start looking for match */
+    win_T       *win,          /* window in which to search or NULL */
+    buf_T       *buf,          /* buffer in which to search */
+    linenr_T   lnum,           /* nr of line to start looking for match */
+    colnr_T    col,            /* column to start looking for match */
     proftime_T *tm,            /* timeout limit or NULL */
     int                *timed_out)     /* flag is set when timeout limit reached */
 {
index 70003a05ba0055845d56b10f62b6c55c1a7c6c94..90fff64b5e8df15a818292ca498c31ee3fc78f73 100644 (file)
@@ -7334,14 +7334,13 @@ nfa_regcomp(char_u *expr, int re_flags)
     nfa_regengine.expr = NULL;
 
 out:
-    vim_free(post_start);
-    post_start = post_ptr = post_end = NULL;
+    VIM_CLEAR(post_start);
+    post_ptr = post_end = NULL;
     state_ptr = NULL;
     return (regprog_T *)prog;
 
 fail:
-    vim_free(prog);
-    prog = NULL;
+    VIM_CLEAR(prog);
 #ifdef ENABLE_LOG
     nfa_postfix_dump(expr, FAIL);
 #endif
index f365be2231b218f073736e7bd5e558ab85f4b75d..ce9b6e98e8c3f28120f69fa582409b87b813d10f 100644 (file)
@@ -4326,10 +4326,7 @@ win_line(
 #endif
 
            if (p_extra_free != NULL)
-           {
-               vim_free(p_extra_free);
-               p_extra_free = NULL;
-           }
+               VIM_CLEAR(p_extra_free);
            /*
             * Get a character from the line itself.
             */
@@ -8860,27 +8857,17 @@ give_up:
             * and over again. */
            done_outofmem_msg = TRUE;
        }
-       vim_free(new_ScreenLines);
-       new_ScreenLines = NULL;
+       VIM_CLEAR(new_ScreenLines);
 #ifdef FEAT_MBYTE
-       vim_free(new_ScreenLinesUC);
-       new_ScreenLinesUC = NULL;
+       VIM_CLEAR(new_ScreenLinesUC);
        for (i = 0; i < p_mco; ++i)
-       {
-           vim_free(new_ScreenLinesC[i]);
-           new_ScreenLinesC[i] = NULL;
-       }
-       vim_free(new_ScreenLines2);
-       new_ScreenLines2 = NULL;
+           VIM_CLEAR(new_ScreenLinesC[i]);
+       VIM_CLEAR(new_ScreenLines2);
 #endif
-       vim_free(new_ScreenAttrs);
-       new_ScreenAttrs = NULL;
-       vim_free(new_LineOffset);
-       new_LineOffset = NULL;
-       vim_free(new_LineWraps);
-       new_LineWraps = NULL;
-       vim_free(new_TabPageIdxs);
-       new_TabPageIdxs = NULL;
+       VIM_CLEAR(new_ScreenAttrs);
+       VIM_CLEAR(new_LineOffset);
+       VIM_CLEAR(new_LineWraps);
+       VIM_CLEAR(new_TabPageIdxs);
     }
     else
     {
index 7f019ed702560695e4e74a70fbbb3efb51faaa38..d3c6518295ed9fb24f3a41ef7078b3b850ea370c 100644 (file)
@@ -5059,8 +5059,7 @@ find_pattern_in_path(
                                prev_fname = NULL;
                            }
                        }
-                       vim_free(new_fname);
-                       new_fname = NULL;
+                       VIM_CLEAR(new_fname);
                        already_searched = TRUE;
                        break;
                    }
index cdcf822957693663f25b495b82cd3dc98d7a2a84..3c53d1d250ac3f08a90187d5e71b6f9131f25517 100644 (file)
@@ -1994,19 +1994,13 @@ slang_clear(slang_T *lp)
     int                i;
     int                round;
 
-    vim_free(lp->sl_fbyts);
-    lp->sl_fbyts = NULL;
-    vim_free(lp->sl_kbyts);
-    lp->sl_kbyts = NULL;
-    vim_free(lp->sl_pbyts);
-    lp->sl_pbyts = NULL;
-
-    vim_free(lp->sl_fidxs);
-    lp->sl_fidxs = NULL;
-    vim_free(lp->sl_kidxs);
-    lp->sl_kidxs = NULL;
-    vim_free(lp->sl_pidxs);
-    lp->sl_pidxs = NULL;
+    VIM_CLEAR(lp->sl_fbyts);
+    VIM_CLEAR(lp->sl_kbyts);
+    VIM_CLEAR(lp->sl_pbyts);
+
+    VIM_CLEAR(lp->sl_fidxs);
+    VIM_CLEAR(lp->sl_kidxs);
+    VIM_CLEAR(lp->sl_pidxs);
 
     for (round = 1; round <= 2; ++round)
     {
@@ -2048,26 +2042,19 @@ slang_clear(slang_T *lp)
     for (i = 0; i < lp->sl_prefixcnt; ++i)
        vim_regfree(lp->sl_prefprog[i]);
     lp->sl_prefixcnt = 0;
-    vim_free(lp->sl_prefprog);
-    lp->sl_prefprog = NULL;
+    VIM_CLEAR(lp->sl_prefprog);
 
-    vim_free(lp->sl_info);
-    lp->sl_info = NULL;
+    VIM_CLEAR(lp->sl_info);
 
-    vim_free(lp->sl_midword);
-    lp->sl_midword = NULL;
+    VIM_CLEAR(lp->sl_midword);
 
     vim_regfree(lp->sl_compprog);
-    vim_free(lp->sl_comprules);
-    vim_free(lp->sl_compstartflags);
-    vim_free(lp->sl_compallflags);
     lp->sl_compprog = NULL;
-    lp->sl_comprules = NULL;
-    lp->sl_compstartflags = NULL;
-    lp->sl_compallflags = NULL;
+    VIM_CLEAR(lp->sl_comprules);
+    VIM_CLEAR(lp->sl_compstartflags);
+    VIM_CLEAR(lp->sl_compallflags);
 
-    vim_free(lp->sl_syllable);
-    lp->sl_syllable = NULL;
+    VIM_CLEAR(lp->sl_syllable);
     ga_clear(&lp->sl_syl_items);
 
     ga_clear_strings(&lp->sl_comppat);
@@ -2094,10 +2081,8 @@ slang_clear(slang_T *lp)
     void
 slang_clear_sug(slang_T *lp)
 {
-    vim_free(lp->sl_sbyts);
-    lp->sl_sbyts = NULL;
-    vim_free(lp->sl_sidxs);
-    lp->sl_sidxs = NULL;
+    VIM_CLEAR(lp->sl_sbyts);
+    VIM_CLEAR(lp->sl_sidxs);
     close_spellbuf(lp->sl_sugbuf);
     lp->sl_sugbuf = NULL;
     lp->sl_sugloaded = FALSE;
@@ -2671,8 +2656,7 @@ clear_midword(win_T *wp)
 {
     vim_memset(wp->w_s->b_spell_ismw, 0, 256);
 #ifdef FEAT_MBYTE
-    vim_free(wp->w_s->b_spell_ismw_mb);
-    wp->w_s->b_spell_ismw_mb = NULL;
+    VIM_CLEAR(wp->w_s->b_spell_ismw_mb);
 #endif
 }
 
@@ -2859,8 +2843,7 @@ spell_delete_wordlist(void)
        mch_remove(int_wordlist);
        int_wordlist_spl(fname);
        mch_remove(fname);
-       vim_free(int_wordlist);
-       int_wordlist = NULL;
+       VIM_CLEAR(int_wordlist);
     }
 }
 
@@ -2887,10 +2870,8 @@ spell_free_all(void)
 
     spell_delete_wordlist();
 
-    vim_free(repl_to);
-    repl_to = NULL;
-    vim_free(repl_from);
-    repl_from = NULL;
+    VIM_CLEAR(repl_to);
+    VIM_CLEAR(repl_from);
 }
 #endif
 
@@ -3425,10 +3406,8 @@ spell_suggest(int count)
     }
     else
     {
-       vim_free(repl_from);
-       repl_from = NULL;
-       vim_free(repl_to);
-       repl_to = NULL;
+       VIM_CLEAR(repl_from);
+       VIM_CLEAR(repl_to);
 
 #ifdef FEAT_RIGHTLEFT
        /* When 'rightleft' is set the list is drawn right-left. */
index e5cc84164ba6d2d24e1acd4d5d05810fdf865665..e9eacbecb69898a8fb5e414adc2ac06edd66b466 100644 (file)
@@ -1352,8 +1352,7 @@ read_compound(FILE *fd, slang_T *slang, int len)
        {
            if (c == '?' || c == '+' || c == '*')
            {
-               vim_free(slang->sl_comprules);
-               slang->sl_comprules = NULL;
+               VIM_CLEAR(slang->sl_comprules);
                crp = NULL;
            }
            else
index d247e0d16f30e106cb427c7754b8733771c3d386..e85dca76daf86c32874a9f00479da9e5f341eb72 100644 (file)
@@ -1189,8 +1189,7 @@ syn_stack_free_block(synblock_T *block)
     {
        for (p = block->b_sst_first; p != NULL; p = p->sst_next)
            clear_syn_state(p);
-       vim_free(block->b_sst_array);
-       block->b_sst_array = NULL;
+       VIM_CLEAR(block->b_sst_array);
        block->b_sst_len = 0;
     }
 }
@@ -2134,7 +2133,7 @@ syn_current_attr(
                            r = syn_regexec(&regmatch,
                                             current_lnum,
                                             (colnr_T)lc_col,
-                                            IF_SYN_TIME(&spp->sp_time));
+                                            IF_SYN_TIME(&spp->sp_time));
                            spp->sp_prog = regmatch.regprog;
                            if (!r)
                            {
@@ -3641,8 +3640,7 @@ syntax_clear(synblock_T *block)
 
     vim_regfree(block->b_syn_linecont_prog);
     block->b_syn_linecont_prog = NULL;
-    vim_free(block->b_syn_linecont_pat);
-    block->b_syn_linecont_pat = NULL;
+    VIM_CLEAR(block->b_syn_linecont_pat);
 #ifdef FEAT_FOLDING
     block->b_syn_folditems = 0;
 #endif
@@ -3690,8 +3688,7 @@ syntax_sync_clear(void)
 
     vim_regfree(curwin->w_s->b_syn_linecont_prog);
     curwin->w_s->b_syn_linecont_prog = NULL;
-    vim_free(curwin->w_s->b_syn_linecont_pat);
-    curwin->w_s->b_syn_linecont_pat = NULL;
+    VIM_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. */
@@ -3810,8 +3807,7 @@ syn_cmd_clear(exarg_T *eap, int syncing)
                     */
                    short scl_id = id - SYNID_CLUSTER;
 
-                   vim_free(SYN_CLSTR(curwin->w_s)[scl_id].scl_list);
-                   SYN_CLSTR(curwin->w_s)[scl_id].scl_list = NULL;
+                   VIM_CLEAR(SYN_CLSTR(curwin->w_s)[scl_id].scl_list);
                }
            }
            else
@@ -5954,8 +5950,7 @@ syn_cmd_sync(exarg_T *eap, int syncing UNUSED)
 
                if (curwin->w_s->b_syn_linecont_prog == NULL)
                {
-                   vim_free(curwin->w_s->b_syn_linecont_pat);
-                   curwin->w_s->b_syn_linecont_pat = NULL;
+                   VIM_CLEAR(curwin->w_s->b_syn_linecont_pat);
                    finished = TRUE;
                    break;
                }
@@ -8369,10 +8364,8 @@ highlight_clear(int idx)
     HL_TABLE()[idx].sg_cleared = TRUE;
 
     HL_TABLE()[idx].sg_term = 0;
-    vim_free(HL_TABLE()[idx].sg_start);
-    HL_TABLE()[idx].sg_start = NULL;
-    vim_free(HL_TABLE()[idx].sg_stop);
-    HL_TABLE()[idx].sg_stop = NULL;
+    VIM_CLEAR(HL_TABLE()[idx].sg_start);
+    VIM_CLEAR(HL_TABLE()[idx].sg_stop);
     HL_TABLE()[idx].sg_term_attr = 0;
     HL_TABLE()[idx].sg_cterm = 0;
     HL_TABLE()[idx].sg_cterm_bold = FALSE;
@@ -8381,12 +8374,9 @@ highlight_clear(int idx)
     HL_TABLE()[idx].sg_cterm_attr = 0;
 #if defined(FEAT_GUI) || defined(FEAT_EVAL)
     HL_TABLE()[idx].sg_gui = 0;
-    vim_free(HL_TABLE()[idx].sg_gui_fg_name);
-    HL_TABLE()[idx].sg_gui_fg_name = NULL;
-    vim_free(HL_TABLE()[idx].sg_gui_bg_name);
-    HL_TABLE()[idx].sg_gui_bg_name = NULL;
-    vim_free(HL_TABLE()[idx].sg_gui_sp_name);
-    HL_TABLE()[idx].sg_gui_sp_name = NULL;
+    VIM_CLEAR(HL_TABLE()[idx].sg_gui_fg_name);
+    VIM_CLEAR(HL_TABLE()[idx].sg_gui_bg_name);
+    VIM_CLEAR(HL_TABLE()[idx].sg_gui_sp_name);
 #endif
 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
     HL_TABLE()[idx].sg_gui_fg = INVALCOLOR;
@@ -8400,8 +8390,7 @@ highlight_clear(int idx)
     gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset);
     HL_TABLE()[idx].sg_fontset = NOFONTSET;
 # endif
-    vim_free(HL_TABLE()[idx].sg_font_name);
-    HL_TABLE()[idx].sg_font_name = NULL;
+    VIM_CLEAR(HL_TABLE()[idx].sg_font_name);
     HL_TABLE()[idx].sg_gui_attr = 0;
 #endif
 #ifdef FEAT_EVAL
index cdad6a348a17c07b4c29bc10e898e6dd001e1a9e..90c3960531a7dac4f81071123f3c9a972d240c8b 100644 (file)
--- a/src/tag.c
+++ b/src/tag.c
@@ -1091,8 +1091,7 @@ end_do_tag:
     void
 tag_freematch(void)
 {
-    vim_free(tagmatchname);
-    tagmatchname = NULL;
+    VIM_CLEAR(tagmatchname);
 }
 
     static void
@@ -2620,10 +2619,7 @@ free_tag_stuff(void)
 
 # if defined(FEAT_QUICKFIX)
     if (ptag_entry.tagname)
-    {
-       vim_free(ptag_entry.tagname);
-       ptag_entry.tagname = NULL;
-    }
+       VIM_CLEAR(ptag_entry.tagname);
 # endif
 }
 #endif
index 6303e10d59f7a4faf997f7414cce6d197d9d5fa3..1f17d9f2fa91ec634f7af2109b0a43bf04e7f053 100644 (file)
@@ -2502,7 +2502,8 @@ out_flush(void)
 }
 
 /*
- * out_flush_cursor(): flush the output buffer and redraw the cursor
+ * out_flush_cursor(): flush the output buffer and redraw the cursor.
+ * Does not flush recursively in the GUI to avoid slow drawing.
  */
     void
 out_flush_cursor(
@@ -3912,8 +3913,7 @@ clear_termcodes(void)
 {
     while (tc_len > 0)
        vim_free(termcodes[--tc_len].code);
-    vim_free(termcodes);
-    termcodes = NULL;
+    VIM_CLEAR(termcodes);
     tc_max_len = 0;
 
 #ifdef HAVE_TGETENT
@@ -5648,7 +5648,7 @@ check_termcode(
            /* Work out our pseudo mouse event. Note that MOUSE_RELEASE gets
             * added, then it's not mouse up/down. */
            key_name[0] = (int)KS_EXTRA;
-            if (wheel_code != 0
+           if (wheel_code != 0
                              && (wheel_code & MOUSE_RELEASE) != MOUSE_RELEASE)
            {
                if (wheel_code & MOUSE_CTRL)
index 02d071525ac3fb0e0e47fbf76cbb1a284f68cfc3..b67cd6ceb4cf7e49798666d479b7aae51c39de44 100644 (file)
@@ -1176,8 +1176,7 @@ move_terminal_to_buffer(term_T *term)
 set_terminal_mode(term_T *term, int normal_mode)
 {
     term->tl_normal_mode = normal_mode;
-    vim_free(term->tl_status_text);
-    term->tl_status_text = NULL;
+    VIM_CLEAR(term->tl_status_text);
     if (term->tl_buffer == curbuf)
        maketitle();
 }
@@ -1739,10 +1738,8 @@ term_job_ended(job_T *job)
     for (term = first_term; term != NULL; term = term->tl_next)
        if (term->tl_job == job)
        {
-           vim_free(term->tl_title);
-           term->tl_title = NULL;
-           vim_free(term->tl_status_text);
-           term->tl_status_text = NULL;
+           VIM_CLEAR(term->tl_title);
+           VIM_CLEAR(term->tl_status_text);
            redraw_buf_and_status_later(term->tl_buffer, VALID);
            did_one = TRUE;
        }
@@ -2023,8 +2020,7 @@ handle_settermprop(
 #endif
            else
                term->tl_title = vim_strsave((char_u *)value->string);
-           vim_free(term->tl_status_text);
-           term->tl_status_text = NULL;
+           VIM_CLEAR(term->tl_status_text);
            if (term == curbuf->b_term)
                maketitle();
            break;
@@ -2189,10 +2185,8 @@ term_channel_closed(channel_T *ch)
            term->tl_channel_closed = TRUE;
            did_one = TRUE;
 
-           vim_free(term->tl_title);
-           term->tl_title = NULL;
-           vim_free(term->tl_status_text);
-           term->tl_status_text = NULL;
+           VIM_CLEAR(term->tl_title);
+           VIM_CLEAR(term->tl_status_text);
 
            /* Unless in Terminal-Normal mode: clear the vterm. */
            if (!term->tl_normal_mode)
index c77a8e029fe3b02d6e29b3e9733f554e96081a22..5cccd4457def94a67ef34c8c7a0e4c9ca518e756 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
@@ -130,8 +130,7 @@ ui_inchar(
        if (maxlen >= ta_len - ta_off)
        {
            mch_memmove(buf, ta_str + ta_off, (size_t)ta_len);
-           vim_free(ta_str);
-           ta_str = NULL;
+           VIM_CLEAR(ta_str);
            return ta_len;
        }
        mch_memmove(buf, ta_str + ta_off, (size_t)maxlen);
@@ -1840,10 +1839,7 @@ fill_input_buf(int exit_on_error UNUSED)
            unconverted = restlen;
        mch_memmove(inbuf + inbufcount, rest, unconverted);
        if (unconverted == restlen)
-       {
-           vim_free(rest);
-           rest = NULL;
-       }
+           VIM_CLEAR(rest);
        else
        {
            restlen -= unconverted;
index 0297e3f661d1ba380493019e16bda39ba53d858b..c723eba6cc0c29c9c5a13f8b926229a1b9f8d0a3 100644 (file)
@@ -849,8 +849,7 @@ u_get_undo_file_name(char_u *buf_ffname, int reading)
        if (undo_file_name != NULL && (!reading
                               || mch_stat((char *)undo_file_name, &st) >= 0))
            break;
-       vim_free(undo_file_name);
-       undo_file_name = NULL;
+       VIM_CLEAR(undo_file_name);
     }
 
     vim_free(munged_name);
@@ -3454,8 +3453,7 @@ u_clearline(void)
 {
     if (curbuf->b_u_line_ptr != NULL)
     {
-       vim_free(curbuf->b_u_line_ptr);
-       curbuf->b_u_line_ptr = NULL;
+       VIM_CLEAR(curbuf->b_u_line_ptr);
        curbuf->b_u_line_lnum = 0;
     }
 }
index 931683d7c8f8ccb6ec4b802049c4acf98d5eadec..df72e34a840d315a435fc1bbaa569983d2749431 100644 (file)
@@ -2122,10 +2122,7 @@ 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)
-           {
-               vim_free(skip_until);
-               skip_until = NULL;
-           }
+               VIM_CLEAR(skip_until);
        }
        else
        {
@@ -2295,8 +2292,7 @@ ex_function(exarg_T *eap)
                /* redefine existing function */
                ga_clear_strings(&(fp->uf_args));
                ga_clear_strings(&(fp->uf_lines));
-               vim_free(name);
-               name = NULL;
+               VIM_CLEAR(name);
            }
        }
     }
index 3a354753a26b35607195d971cef6bf5ab60e1b02..dbd272109b68d97f8c28f818c45ee205ca6fb93f 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1496,
 /**/
     1495,
 /**/
index 669f3bd6e856dee58b1f995323433f9aab30389d..38e1591cceb5efd5f2adce62ef326fa7004c2b3e 100644 (file)
@@ -4415,8 +4415,7 @@ win_enter_ext(
        /* Window doesn't have a local directory and we are not in the global
         * directory: Change to the global directory. */
        ignored = mch_chdir((char *)globaldir);
-       vim_free(globaldir);
-       globaldir = NULL;
+       VIM_CLEAR(globaldir);
        shorten_fnames(TRUE);
     }
 
@@ -4847,10 +4846,7 @@ win_free_lsize(win_T *wp)
 {
     /* TODO: why would wp be NULL here? */
     if (wp != NULL)
-    {
-       vim_free(wp->w_lines);
-       wp->w_lines = NULL;
-    }
+       VIM_CLEAR(wp->w_lines);
 }
 
 /*