Merge PR #2415 'Use jemalloc instead of libc allocator'

This commit is contained in:
Thiago de Arruda 2015-04-13 09:30:57 -03:00
commit a9ee85b9fc
79 changed files with 1519 additions and 1420 deletions

View File

@ -202,6 +202,29 @@ option(LIBVTERM_USE_STATIC "Use static libvterm" ON)
find_package(LibVterm REQUIRED) find_package(LibVterm REQUIRED)
include_directories(SYSTEM ${LIBVTERM_INCLUDE_DIRS}) include_directories(SYSTEM ${LIBVTERM_INCLUDE_DIRS})
option(SANITIZE "Enable Clang sanitizers for nvim binary" OFF)
if(SANITIZE AND NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
message(WARNING "SANITIZE is only supported for Clang ... disabling")
set(SANITIZE OFF)
endif()
if(SANITIZE)
option(USE_JEMALLOC "Use jemalloc" OFF)
else()
option(USE_JEMALLOC "Use jemalloc" ON)
endif()
if(USE_JEMALLOC)
option(JEMALLOC_USE_STATIC "Use static jemalloc" ON)
find_package(JeMalloc)
if(JEMALLOC_FOUND)
message(STATUS "Using jemalloc instead of libc allocator")
include_directories(SYSTEM ${JEMALLOC_INCLUDE_DIRS})
else()
set(USE_JEMALLOC OFF)
endif()
endif()
find_package(LibIntl) find_package(LibIntl)
if(LibIntl_FOUND) if(LibIntl_FOUND)
include_directories(SYSTEM ${LibIntl_INCLUDE_DIRS}) include_directories(SYSTEM ${LibIntl_INCLUDE_DIRS})

View File

@ -1274,6 +1274,39 @@ def CheckPosixThreading(filename, clean_lines, linenum, error):
' see os_localtime_r for an example.') ' see os_localtime_r for an example.')
memory_functions = (
('malloc(', 'xmalloc('),
('calloc(', 'xcalloc('),
('realloc(', 'xrealloc('),
('strdup(', 'xstrdup('),
('free(', 'xfree('),
)
memory_ignore_pattern = re.compile(r'src/nvim/memory.c$')
def CheckMemoryFunctions(filename, clean_lines, linenum, error):
"""Checks for calls to invalid functions.
Args:
filename: The name of the current file.
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
error: The function to call with any errors found.
"""
if memory_ignore_pattern.search(filename):
return
line = clean_lines.elided[linenum]
for function, suggested_function in memory_functions:
ix = line.find(function)
# Comparisons made explicit for clarity -- pylint:
# disable=g-explicit-bool-comparison
if ix >= 0 and (ix == 0 or (not line[ix - 1].isalnum() and
line[ix - 1] not in ('_', '.', '>'))):
error(filename, linenum, 'runtime/memory_fn', 2,
'Use ' + suggested_function +
'...) instead of ' + function + '...).')
# Matches invalid increment: *count++, which moves pointer instead of # Matches invalid increment: *count++, which moves pointer instead of
# incrementing a value. # incrementing a value.
_RE_PATTERN_INVALID_INCREMENT = re.compile( _RE_PATTERN_INVALID_INCREMENT = re.compile(
@ -2925,6 +2958,7 @@ def ProcessLine(filename, file_extension, clean_lines, line,
CheckForNonStandardConstructs(filename, clean_lines, line, CheckForNonStandardConstructs(filename, clean_lines, line,
nesting_state, error) nesting_state, error)
CheckPosixThreading(filename, clean_lines, line, error) CheckPosixThreading(filename, clean_lines, line, error)
CheckMemoryFunctions(filename, clean_lines, line, error)
for check_fn in extra_check_functions: for check_fn in extra_check_functions:
check_fn(filename, clean_lines, line, error) check_fn(filename, clean_lines, line, error)

48
cmake/FindJeMalloc.cmake Normal file
View File

@ -0,0 +1,48 @@
# - Try to find jemalloc
# Once done this will define
# JEMALLOC_FOUND - System has jemalloc
# JEMALLOC_INCLUDE_DIRS - The jemalloc include directories
# JEMALLOC_LIBRARIES - The libraries needed to use jemalloc
find_package(PkgConfig)
if(NOT JEMALLOC_USE_BUNDLED)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(PC_JEMALLOC QUIET jemalloc)
endif()
else()
set(PC_JEMALLOC_INCLUDEDIR)
set(PC_JEMALLOC_INCLUDE_DIRS)
set(PC_JEMALLOC_LIBDIR)
set(PC_JEMALLOC_LIBRARY_DIRS)
set(LIMIT_SEARCH NO_DEFAULT_PATH)
endif()
set(JEMALLOC_DEFINITIONS ${PC_JEMALLOC_CFLAGS_OTHER})
find_path(JEMALLOC_INCLUDE_DIR jemalloc/jemalloc.h
PATHS ${PC_JEMALLOC_INCLUDEDIR} ${PC_JEMALLOC_INCLUDE_DIRS}
${LIMIT_SEARCH})
# If we're asked to use static linkage, add libjemalloc.a as a preferred library name.
if(JEMALLOC_USE_STATIC)
list(APPEND JEMALLOC_NAMES
"${CMAKE_STATIC_LIBRARY_PREFIX}jemalloc${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()
list(APPEND JEMALLOC_NAMES jemalloc)
find_library(JEMALLOC_LIBRARY NAMES ${JEMALLOC_NAMES}
HINTS ${PC_JEMALLOC_LIBDIR} ${PC_JEMALLOC_LIBRARY_DIRS}
${LIMIT_SEARCH})
set(JEMALLOC_LIBRARIES ${JEMALLOC_LIBRARY})
set(JEMALLOC_INCLUDE_DIRS ${JEMALLOC_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set JEMALLOC_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(JeMalloc DEFAULT_MSG
JEMALLOC_LIBRARY JEMALLOC_INCLUDE_DIR)
mark_as_advanced(JEMALLOC_INCLUDE_DIR JEMALLOC_LIBRARY)

View File

@ -65,5 +65,6 @@
#define FEAT_BROWSE #define FEAT_BROWSE
#define FEAT_CSCOPE #define FEAT_CSCOPE
#define FEAT_MOUSE #define FEAT_MOUSE
#cmakedefine USE_JEMALLOC
#endif // AUTO_CONFIG_H #endif // AUTO_CONFIG_H

View File

@ -1,11 +1,5 @@
include(CheckLibraryExists) include(CheckLibraryExists)
option(SANITIZE "Enable Clang sanitizers for nvim binary" OFF)
if(SANITIZE AND NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
message(WARNING "SANITIZE is only supported for Clang ... disabling")
set(SANITIZE OFF)
endif()
set(GENERATED_DIR ${PROJECT_BINARY_DIR}/src/nvim/auto) set(GENERATED_DIR ${PROJECT_BINARY_DIR}/src/nvim/auto)
set(DISPATCH_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/msgpack-gen.lua) set(DISPATCH_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/msgpack-gen.lua)
file(GLOB API_HEADERS api/*.h) file(GLOB API_HEADERS api/*.h)
@ -176,9 +170,16 @@ list(APPEND NVIM_LINK_LIBRARIES
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
) )
set(NVIM_EXEC_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES})
if(USE_JEMALLOC)
# dont use jemalloc in the unit test library
list(APPEND NVIM_EXEC_LINK_LIBRARIES ${JEMALLOC_LIBRARIES})
endif()
add_executable(nvim ${NEOVIM_GENERATED_SOURCES} ${NEOVIM_SOURCES} add_executable(nvim ${NEOVIM_GENERATED_SOURCES} ${NEOVIM_SOURCES}
${NEOVIM_HEADERS}) ${NEOVIM_HEADERS})
target_link_libraries(nvim ${NVIM_LINK_LIBRARIES}) target_link_libraries(nvim ${NVIM_EXEC_LINK_LIBRARIES})
install_helper(TARGETS nvim) install_helper(TARGETS nvim)
if(SANITIZE) if(SANITIZE)
@ -199,5 +200,6 @@ set_property(TARGET libnvim APPEND_STRING PROPERTY COMPILE_FLAGS " -DMAKE_LIB ")
add_library(nvim-test MODULE EXCLUDE_FROM_ALL ${NEOVIM_GENERATED_SOURCES} add_library(nvim-test MODULE EXCLUDE_FROM_ALL ${NEOVIM_GENERATED_SOURCES}
${NEOVIM_SOURCES} ${NEOVIM_HEADERS}) ${NEOVIM_SOURCES} ${NEOVIM_HEADERS})
target_link_libraries(nvim-test ${NVIM_LINK_LIBRARIES}) target_link_libraries(nvim-test ${NVIM_LINK_LIBRARIES})
set_target_properties(nvim-test PROPERTIES COMPILE_FLAGS -DUNIT_TESTING)
add_subdirectory(po) add_subdirectory(po)

View File

@ -58,7 +58,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
rv = slice.items[0].data.string; rv = slice.items[0].data.string;
} }
free(slice.items); xfree(slice.items);
return rv; return rv;
} }
@ -144,10 +144,10 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer,
end: end:
if (err->set) { if (err->set) {
for (size_t i = 0; i < rv.size; i++) { for (size_t i = 0; i < rv.size; i++) {
free(rv.items[i].data.string.data); xfree(rv.items[i].data.string.data);
} }
free(rv.items); xfree(rv.items);
rv.items = NULL; rv.items = NULL;
} }
@ -280,7 +280,7 @@ void buffer_set_line_slice(Buffer buffer,
} }
// Same as with replacing, but we also need to free lines // Same as with replacing, but we also need to free lines
free(lines[i]); xfree(lines[i]);
lines[i] = NULL; lines[i] = NULL;
extra++; extra++;
} }
@ -301,10 +301,10 @@ void buffer_set_line_slice(Buffer buffer,
end: end:
for (size_t i = 0; i < new_len; i++) { for (size_t i = 0; i < new_len; i++) {
free(lines[i]); xfree(lines[i]);
} }
free(lines); xfree(lines);
restore_win_for_buf(save_curwin, save_curtab, save_curbuf); restore_win_for_buf(save_curwin, save_curtab, save_curbuf);
try_end(err); try_end(err);
} }

View File

@ -61,7 +61,7 @@ bool try_end(Error *err)
free_global_msglist(); free_global_msglist();
if (should_free) { if (should_free) {
free(msg); xfree(msg);
} }
} else if (did_throw) { } else if (did_throw) {
api_set_error(err, Exception, "%s", current_exception->value); api_set_error(err, Exception, "%s", current_exception->value);
@ -489,7 +489,7 @@ void api_free_string(String value)
return; return;
} }
free(value.data); xfree(value.data);
} }
void api_free_object(Object value) void api_free_object(Object value)
@ -527,7 +527,7 @@ void api_free_array(Array value)
api_free_object(value.items[i]); api_free_object(value.items[i]);
} }
free(value.items); xfree(value.items);
} }
void api_free_dictionary(Dictionary value) void api_free_dictionary(Dictionary value)
@ -537,7 +537,7 @@ void api_free_dictionary(Dictionary value)
api_free_object(value.items[i].value); api_free_object(value.items[i].value);
} }
free(value.items); xfree(value.items);
} }
Dictionary api_metadata(void) Dictionary api_metadata(void)

View File

@ -85,7 +85,7 @@ void vim_feedkeys(String keys, String mode, Boolean escape_csi)
insert ? 0 : typebuf.tb_len, !typed, false); insert ? 0 : typebuf.tb_len, !typed, false);
if (escape_csi) { if (escape_csi) {
free(keys_esc); xfree(keys_esc);
} }
if (vgetc_busy) if (vgetc_busy)

View File

@ -443,8 +443,8 @@ close_buffer (
* Remove the buffer from the list. * Remove the buffer from the list.
*/ */
if (wipe_buf) { if (wipe_buf) {
free(buf->b_ffname); xfree(buf->b_ffname);
free(buf->b_sfname); xfree(buf->b_sfname);
if (buf->b_prev == NULL) if (buf->b_prev == NULL)
firstbuf = buf->b_next; firstbuf = buf->b_next;
else else
@ -563,7 +563,7 @@ static void free_buffer(buf_T *buf)
buf->b_next = au_pending_free_buf; buf->b_next = au_pending_free_buf;
au_pending_free_buf = buf; au_pending_free_buf = buf;
} else { } else {
free(buf); xfree(buf);
} }
} }
@ -587,7 +587,7 @@ free_buffer_stuff (
buf_delete_signs(buf); /* delete any signs */ buf_delete_signs(buf); /* delete any signs */
map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); /* clear local mappings */ map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); /* clear local mappings */
map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); /* clear local abbrevs */ map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); /* clear local abbrevs */
free(buf->b_start_fenc); xfree(buf->b_start_fenc);
buf->b_start_fenc = NULL; buf->b_start_fenc = NULL;
} }
@ -605,7 +605,7 @@ static void clear_wininfo(buf_T *buf)
clear_winopt(&wip->wi_opt); clear_winopt(&wip->wi_opt);
deleteFoldRecurse(&wip->wi_folds); deleteFoldRecurse(&wip->wi_folds);
} }
free(wip); xfree(wip);
} }
} }
@ -1332,7 +1332,7 @@ buflist_new (
if (ffname != NULL && !(flags & BLN_DUMMY) if (ffname != NULL && !(flags & BLN_DUMMY)
&& (buf = buflist_findname_file_id(ffname, &file_id, && (buf = buflist_findname_file_id(ffname, &file_id,
file_id_valid)) != NULL) { file_id_valid)) != NULL) {
free(ffname); xfree(ffname);
if (lnum != 0) if (lnum != 0)
buflist_setfpos(buf, curwin, lnum, (colnr_T)0, FALSE); buflist_setfpos(buf, curwin, lnum, (colnr_T)0, FALSE);
/* copy the options now, if 'cpo' doesn't have 's' and not done /* copy the options now, if 'cpo' doesn't have 's' and not done
@ -1396,9 +1396,9 @@ buflist_new (
buf->b_wininfo = xcalloc(1, sizeof(wininfo_T)); buf->b_wininfo = xcalloc(1, sizeof(wininfo_T));
if (ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL)) { if (ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL)) {
free(buf->b_ffname); xfree(buf->b_ffname);
buf->b_ffname = NULL; buf->b_ffname = NULL;
free(buf->b_sfname); xfree(buf->b_sfname);
buf->b_sfname = NULL; buf->b_sfname = NULL;
if (buf != curbuf) if (buf != curbuf)
free_buffer(buf); free_buffer(buf);
@ -1672,7 +1672,7 @@ buf_T *buflist_findname_exp(char_u *fname)
); );
if (ffname != NULL) { if (ffname != NULL) {
buf = buflist_findname(ffname); buf = buflist_findname(ffname);
free(ffname); xfree(ffname);
} }
return buf; return buf;
} }
@ -1767,7 +1767,7 @@ buflist_findpat (
++p; ++p;
prog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); prog = vim_regcomp(p, p_magic ? RE_MAGIC : 0);
if (prog == NULL) { if (prog == NULL) {
free(pat); xfree(pat);
return -1; return -1;
} }
@ -1809,7 +1809,7 @@ buflist_findpat (
find_listed = FALSE; find_listed = FALSE;
} }
free(pat); xfree(pat);
} }
if (match == -2) if (match == -2)
@ -1855,7 +1855,7 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options)
prog = vim_regcomp(patc + attempt * 11, RE_MAGIC); prog = vim_regcomp(patc + attempt * 11, RE_MAGIC);
if (prog == NULL) { if (prog == NULL) {
if (patc != pat) if (patc != pat)
free(patc); xfree(patc);
return FAIL; return FAIL;
} }
@ -1893,7 +1893,7 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options)
} }
if (patc != pat) if (patc != pat)
free(patc); xfree(patc);
*num_file = count; *num_file = count;
return count == 0 ? FAIL : OK; return count == 0 ? FAIL : OK;
@ -1938,7 +1938,7 @@ static char_u *fname_match(regprog_T *prog, char_u *name, bool ignore_case)
p = home_replace_save(NULL, name); p = home_replace_save(NULL, name);
if (vim_regexec(&regmatch, p, (colnr_T)0)) if (vim_regexec(&regmatch, p, (colnr_T)0))
match = name; match = name;
free(p); xfree(p);
} }
} }
@ -2223,8 +2223,8 @@ setfname (
if (ffname == NULL || *ffname == NUL) { if (ffname == NULL || *ffname == NUL) {
/* Removing the name. */ /* Removing the name. */
free(buf->b_ffname); xfree(buf->b_ffname);
free(buf->b_sfname); xfree(buf->b_sfname);
buf->b_ffname = NULL; buf->b_ffname = NULL;
buf->b_sfname = NULL; buf->b_sfname = NULL;
} else { } else {
@ -2245,7 +2245,7 @@ setfname (
if (obuf->b_ml.ml_mfp != NULL) { /* it's loaded, fail */ if (obuf->b_ml.ml_mfp != NULL) { /* it's loaded, fail */
if (message) if (message)
EMSG(_("E95: Buffer with this name already exists")); EMSG(_("E95: Buffer with this name already exists"));
free(ffname); xfree(ffname);
return FAIL; return FAIL;
} }
/* delete from the list */ /* delete from the list */
@ -2255,8 +2255,8 @@ setfname (
#ifdef USE_FNAME_CASE #ifdef USE_FNAME_CASE
path_fix_case(sfname); /* set correct case for short file name */ path_fix_case(sfname); /* set correct case for short file name */
#endif #endif
free(buf->b_ffname); xfree(buf->b_ffname);
free(buf->b_sfname); xfree(buf->b_sfname);
buf->b_ffname = ffname; buf->b_ffname = ffname;
buf->b_sfname = sfname; buf->b_sfname = sfname;
} }
@ -2282,8 +2282,8 @@ void buf_set_name(int fnum, char_u *name)
buf = buflist_findnr(fnum); buf = buflist_findnr(fnum);
if (buf != NULL) { if (buf != NULL) {
free(buf->b_sfname); xfree(buf->b_sfname);
free(buf->b_ffname); xfree(buf->b_ffname);
buf->b_ffname = vim_strsave(name); buf->b_ffname = vim_strsave(name);
buf->b_sfname = NULL; buf->b_sfname = NULL;
/* Allocate ffname and expand into full path. Also resolves .lnk /* Allocate ffname and expand into full path. Also resolves .lnk
@ -2561,7 +2561,7 @@ fileinfo (
set_keep_msg(p, 0); set_keep_msg(p, 0);
} }
free(buffer); xfree(buffer);
} }
void col_print(char_u *buf, size_t buflen, int col, int vcol) void col_print(char_u *buf, size_t buflen, int col, int vcol)
@ -2636,7 +2636,7 @@ void maketitle(void)
else { else {
p = transstr(path_tail(curbuf->b_fname)); p = transstr(path_tail(curbuf->b_fname));
STRLCPY(buf, p, SPACE_FOR_FNAME + 1); STRLCPY(buf, p, SPACE_FOR_FNAME + 1);
free(p); xfree(p);
} }
switch (bufIsChanged(curbuf) switch (bufIsChanged(curbuf)
@ -2677,7 +2677,7 @@ void maketitle(void)
if (off < SPACE_FOR_DIR) { if (off < SPACE_FOR_DIR) {
p = transstr(buf + off); p = transstr(buf + off);
STRLCPY(buf + off, p, SPACE_FOR_DIR - off + 1); STRLCPY(buf + off, p, SPACE_FOR_DIR - off + 1);
free(p); xfree(p);
} else { } else {
STRLCPY(buf + off, "...", SPACE_FOR_ARGNR - off + 1); STRLCPY(buf + off, "...", SPACE_FOR_ARGNR - off + 1);
} }
@ -2749,7 +2749,7 @@ static int ti_change(char_u *str, char_u **last)
{ {
if ((str == NULL) != (*last == NULL) if ((str == NULL) != (*last == NULL)
|| (str != NULL && *last != NULL && STRCMP(str, *last) != 0)) { || (str != NULL && *last != NULL && STRCMP(str, *last) != 0)) {
free(*last); xfree(*last);
if (str == NULL) if (str == NULL)
*last = NULL; *last = NULL;
else else
@ -2771,8 +2771,8 @@ void resettitle(void)
# if defined(EXITFREE) # if defined(EXITFREE)
void free_titles(void) void free_titles(void)
{ {
free(lasttitle); xfree(lasttitle);
free(lasticon); xfree(lasticon);
} }
# endif # endif
@ -3124,7 +3124,7 @@ build_stl_str_hl (
if (str != NULL && *str != 0) { if (str != NULL && *str != 0) {
if (*skipdigits(str) == NUL) { if (*skipdigits(str) == NUL) {
num = atoi((char *)str); num = atoi((char *)str);
free(str); xfree(str);
str = NULL; str = NULL;
itemisflag = FALSE; itemisflag = FALSE;
} }
@ -3381,7 +3381,7 @@ build_stl_str_hl (
item[curitem].type = Empty; item[curitem].type = Empty;
if (opt == STL_VIM_EXPR) if (opt == STL_VIM_EXPR)
free(str); xfree(str);
if (num >= 0 || (!itemisflag && str && *str)) if (num >= 0 || (!itemisflag && str && *str))
prevchar_isflag = FALSE; /* Item not NULL, but not a flag */ prevchar_isflag = FALSE; /* Item not NULL, but not a flag */
@ -3391,7 +3391,7 @@ build_stl_str_hl (
itemcnt = curitem; itemcnt = curitem;
if (usefmt != fmt) if (usefmt != fmt)
free(usefmt); xfree(usefmt);
width = vim_strsize(out); width = vim_strsize(out);
if (maxwidth > 0 && width > maxwidth) { if (maxwidth > 0 && width > maxwidth) {
@ -3585,7 +3585,7 @@ void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname)
/* If the file name is a shortcut file, use the file it links to. */ /* If the file name is a shortcut file, use the file it links to. */
rfname = mch_resolve_shortcut(*ffname); rfname = mch_resolve_shortcut(*ffname);
if (rfname != NULL) { if (rfname != NULL) {
free(*ffname); xfree(*ffname);
*ffname = rfname; *ffname = rfname;
*sfname = rfname; *sfname = rfname;
} }
@ -3844,7 +3844,7 @@ do_arg_all (
win_enter(new_curwin, false); win_enter(new_curwin, false);
--autocmd_no_leave; --autocmd_no_leave;
free(opened); xfree(opened);
} }
/* /*
@ -4161,7 +4161,7 @@ chk_modeline (
sourcing_lnum = save_sourcing_lnum; sourcing_lnum = save_sourcing_lnum;
sourcing_name = save_sourcing_name; sourcing_name = save_sourcing_name;
free(linecopy); xfree(linecopy);
return retval; return retval;
} }
@ -4208,7 +4208,7 @@ int read_viminfo_bufferlist(vir_T *virp, int writing)
buflist_setfpos(buf, curwin, lnum, col, FALSE); buflist_setfpos(buf, curwin, lnum, col, FALSE);
} }
} }
free(xline); xfree(xline);
return viminfo_readline(virp); return viminfo_readline(virp);
} }
@ -4249,7 +4249,7 @@ void write_viminfo_bufferlist(FILE *fp)
buf->b_last_cursor.col); buf->b_last_cursor.col);
viminfo_writestring(fp, line); viminfo_writestring(fp, line);
} }
free(line); xfree(line);
} }
@ -4426,7 +4426,7 @@ linenr_T buf_delsign(
if (sign->id == id) { if (sign->id == id) {
*lastp = next; *lastp = next;
lnum = sign->lnum; lnum = sign->lnum;
free(sign); xfree(sign);
break; break;
} else { } else {
lastp = &sign->next; lastp = &sign->next;
@ -4498,7 +4498,7 @@ void buf_delete_signs(buf_T *buf)
while (buf->b_signlist != NULL) { while (buf->b_signlist != NULL) {
next = buf->b_signlist->next; next = buf->b_signlist->next;
free(buf->b_signlist); xfree(buf->b_signlist);
buf->b_signlist = next; buf->b_signlist = next;
} }
} }
@ -4621,7 +4621,7 @@ int buf_contents_changed(buf_T *buf)
} }
} }
} }
free(ea.cmd); xfree(ea.cmd);
/* restore curwin/curbuf and a few other things */ /* restore curwin/curbuf and a few other things */
aucmd_restbuf(&aco); aucmd_restbuf(&aco);

View File

@ -393,7 +393,7 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1,
} }
} }
dprev->df_next = dp->df_next; dprev->df_next = dp->df_next;
free(dp); xfree(dp);
dp = dprev->df_next; dp = dprev->df_next;
} else { } else {
// Advance to next entry. // Advance to next entry.
@ -416,7 +416,7 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1,
if (i == DB_COUNT) { if (i == DB_COUNT) {
diff_T *dnext = dp->df_next; diff_T *dnext = dp->df_next;
free(dp); xfree(dp);
dp = dnext; dp = dnext;
if (dprev == NULL) { if (dprev == NULL) {
@ -527,7 +527,7 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp)
break; break;
} }
} }
free(line_org); xfree(line_org);
// Stop when a line isn't equal in all diff buffers. // Stop when a line isn't equal in all diff buffers.
if (i_new != DB_COUNT) { if (i_new != DB_COUNT) {
@ -786,9 +786,9 @@ void ex_diffupdate(exarg_T *eap)
diff_redraw(TRUE); diff_redraw(TRUE);
theend: theend:
free(tmp_orig); xfree(tmp_orig);
free(tmp_new); xfree(tmp_new);
free(tmp_diff); xfree(tmp_diff);
} }
/// Make a diff between files "tmp_orig" and "tmp_new", results in "tmp_diff". /// Make a diff between files "tmp_orig" and "tmp_new", results in "tmp_diff".
@ -828,7 +828,7 @@ static void diff_file(char_u *tmp_orig, char_u *tmp_new, char_u *tmp_diff)
NULL NULL
); );
unblock_autocmds(); unblock_autocmds();
free(cmd); xfree(cmd);
} }
} }
@ -989,16 +989,16 @@ theend:
if (tmp_orig != NULL) { if (tmp_orig != NULL) {
os_remove((char *)tmp_orig); os_remove((char *)tmp_orig);
} }
free(tmp_orig); xfree(tmp_orig);
if (tmp_new != NULL) { if (tmp_new != NULL) {
os_remove((char *)tmp_new); os_remove((char *)tmp_new);
} }
free(tmp_new); xfree(tmp_new);
free(newname); xfree(newname);
free(buf); xfree(buf);
#ifdef UNIX #ifdef UNIX
free(fullname); xfree(fullname);
#endif // ifdef UNIX #endif // ifdef UNIX
} }
@ -1340,7 +1340,7 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname)
while (dn != dp->df_next) { while (dn != dp->df_next) {
dpl = dn->df_next; dpl = dn->df_next;
free(dn); xfree(dn);
dn = dpl; dn = dpl;
} }
} else { } else {
@ -1407,7 +1407,7 @@ void diff_clear(tabpage_T *tp)
diff_T *next_p; diff_T *next_p;
for (p = tp->tp_first_diff; p != NULL; p = next_p) { for (p = tp->tp_first_diff; p != NULL; p = next_p) {
next_p = p->df_next; next_p = p->df_next;
free(p); xfree(p);
} }
tp->tp_first_diff = NULL; tp->tp_first_diff = NULL;
} }
@ -1559,7 +1559,7 @@ static int diff_equal_entry(diff_T *dp, int idx1, int idx2)
int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2],
dp->df_lnum[idx2] + i, FALSE)); dp->df_lnum[idx2] + i, FALSE));
free(line); xfree(line);
if (cmp != 0) { if (cmp != 0) {
return FALSE; return FALSE;
@ -1863,7 +1863,7 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
int idx = diff_buf_idx(wp->w_buffer); int idx = diff_buf_idx(wp->w_buffer);
if (idx == DB_COUNT) { if (idx == DB_COUNT) {
// cannot happen // cannot happen
free(line_org); xfree(line_org);
return FALSE; return FALSE;
} }
@ -1876,7 +1876,7 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
} }
if ((dp == NULL) || (diff_check_sanity(curtab, dp) == FAIL)) { if ((dp == NULL) || (diff_check_sanity(curtab, dp) == FAIL)) {
free(line_org); xfree(line_org);
return FALSE; return FALSE;
} }
@ -1956,7 +1956,7 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
} }
} }
free(line_org); xfree(line_org);
return added; return added;
} }
@ -2262,7 +2262,7 @@ void ex_diffgetput(exarg_T *eap)
} }
p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, FALSE)); p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, FALSE));
ml_append(lnum + i - 1, p, 0, FALSE); ml_append(lnum + i - 1, p, 0, FALSE);
free(p); xfree(p);
added++; added++;
if (buf_empty && (curbuf->b_ml.ml_line_count == 2)) { if (buf_empty && (curbuf->b_ml.ml_line_count == 2)) {
// Added the first line into an empty buffer, need to // Added the first line into an empty buffer, need to
@ -2317,7 +2317,7 @@ void ex_diffgetput(exarg_T *eap)
if (dfree != NULL) { if (dfree != NULL) {
// Diff is deleted, update folds in other windows. // Diff is deleted, update folds in other windows.
diff_fold_update(dfree, idx_to); diff_fold_update(dfree, idx_to);
free(dfree); xfree(dfree);
} else { } else {
// mark_adjust() may have changed the count in a wrong way // mark_adjust() may have changed the count in a wrong way
dp->df_count[idx_to] = new_count; dp->df_count[idx_to] = new_count;

View File

@ -1538,7 +1538,7 @@ static int getexactdigraph(int char1, int char2, int meta_char)
if (to != NULL) { if (to != NULL) {
retval = (*mb_ptr2char)(to); retval = (*mb_ptr2char)(to);
free(to); xfree(to);
} }
(void)convert_setup(&vc, NULL, NULL); (void)convert_setup(&vc, NULL, NULL);
} }
@ -1763,11 +1763,11 @@ char_u* keymap_init(void)
curbuf->b_p_keymap); curbuf->b_p_keymap);
if (source_runtime((char_u *)buf, FALSE) == FAIL) { if (source_runtime((char_u *)buf, FALSE) == FAIL) {
free(buf); xfree(buf);
return (char_u *)N_("E544: Keymap file not found"); return (char_u *)N_("E544: Keymap file not found");
} }
} }
free(buf); xfree(buf);
} }
return NULL; return NULL;
@ -1824,12 +1824,12 @@ void ex_loadkeymap(exarg_T *eap)
if (*kp->to == NUL) { if (*kp->to == NUL) {
EMSG(_("E791: Empty keymap entry")); EMSG(_("E791: Empty keymap entry"));
} }
free(kp->from); xfree(kp->from);
free(kp->to); xfree(kp->to);
--curbuf->b_kmap_ga.ga_len; --curbuf->b_kmap_ga.ga_len;
} }
} }
free(line); xfree(line);
} }
// setup ":lnoremap" to map the keys // setup ":lnoremap" to map the keys
@ -1866,8 +1866,8 @@ static void keymap_unload(void)
for (int i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { for (int i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) {
vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from); vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from);
(void)do_map(1, buf, LANGMAP, FALSE); (void)do_map(1, buf, LANGMAP, FALSE);
free(kp[i].from); xfree(kp[i].from);
free(kp[i].to); xfree(kp[i].to);
} }
p_cpo = save_cpo; p_cpo = save_cpo;

View File

@ -482,7 +482,7 @@ edit (
new_insert_skip = 0; new_insert_skip = 0;
else { else {
new_insert_skip = (int)STRLEN(ptr); new_insert_skip = (int)STRLEN(ptr);
free(ptr); xfree(ptr);
} }
old_indent = 0; old_indent = 0;
@ -652,7 +652,7 @@ edit (
if (str != NULL) { if (str != NULL) {
for (p = str; *p != NUL; mb_ptr_adv(p)) for (p = str; *p != NUL; mb_ptr_adv(p))
ins_compl_addleader(PTR2CHAR(p)); ins_compl_addleader(PTR2CHAR(p));
free(str); xfree(str);
} else } else
ins_compl_addleader(c); ins_compl_addleader(c);
continue; continue;
@ -1153,7 +1153,7 @@ normalchar:
} }
AppendToRedobuffLit(str, -1); AppendToRedobuffLit(str, -1);
} }
free(str); xfree(str);
c = NUL; c = NUL;
} }
@ -1569,7 +1569,7 @@ change_indent (
memset(ptr, ' ', i); memset(ptr, ' ', i);
new_cursor_col += i; new_cursor_col += i;
ins_str(ptr); ins_str(ptr);
free(ptr); xfree(ptr);
} }
/* /*
@ -1648,7 +1648,7 @@ change_indent (
/* Insert new stuff into line again */ /* Insert new stuff into line again */
ins_bytes(new_line); ins_bytes(new_line);
free(new_line); xfree(new_line);
} }
} }
@ -1970,7 +1970,7 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int
*(p++) = wca[i++]; *(p++) = wca[i++];
*p = NUL; *p = NUL;
free(wca); xfree(wca);
return ins_compl_add(IObuff, len, icase, fname, NULL, dir, return ins_compl_add(IObuff, len, icase, fname, NULL, dir,
flags, FALSE); flags, FALSE);
@ -2273,7 +2273,7 @@ static void ins_compl_del_pum(void)
{ {
if (compl_match_array != NULL) { if (compl_match_array != NULL) {
pum_undisplay(); pum_undisplay();
free(compl_match_array); xfree(compl_match_array);
compl_match_array = NULL; compl_match_array = NULL;
} }
} }
@ -2490,8 +2490,8 @@ ins_compl_dictionaries (
ptr = xmalloc(len); ptr = xmalloc(len);
vim_snprintf((char *)ptr, len, "^\\s*\\zs\\V%s", pat_esc); vim_snprintf((char *)ptr, len, "^\\s*\\zs\\V%s", pat_esc);
regmatch.regprog = vim_regcomp(ptr, RE_MAGIC); regmatch.regprog = vim_regcomp(ptr, RE_MAGIC);
free(pat_esc); xfree(pat_esc);
free(ptr); xfree(ptr);
} else { } else {
regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
if (regmatch.regprog == NULL) if (regmatch.regprog == NULL)
@ -2539,7 +2539,7 @@ ins_compl_dictionaries (
theend: theend:
p_scs = save_p_scs; p_scs = save_p_scs;
vim_regfree(regmatch.regprog); vim_regfree(regmatch.regprog);
free(buf); xfree(buf);
} }
static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir) static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir)
@ -2689,9 +2689,9 @@ static void ins_compl_free(void)
compl_T *match; compl_T *match;
int i; int i;
free(compl_pattern); xfree(compl_pattern);
compl_pattern = NULL; compl_pattern = NULL;
free(compl_leader); xfree(compl_leader);
compl_leader = NULL; compl_leader = NULL;
if (compl_first_match == NULL) if (compl_first_match == NULL)
@ -2704,13 +2704,13 @@ static void ins_compl_free(void)
do { do {
match = compl_curr_match; match = compl_curr_match;
compl_curr_match = compl_curr_match->cp_next; compl_curr_match = compl_curr_match->cp_next;
free(match->cp_str); xfree(match->cp_str);
/* several entries may use the same fname, free it just once. */ /* several entries may use the same fname, free it just once. */
if (match->cp_flags & FREE_FNAME) if (match->cp_flags & FREE_FNAME)
free(match->cp_fname); xfree(match->cp_fname);
for (i = 0; i < CPT_COUNT; ++i) for (i = 0; i < CPT_COUNT; ++i)
free(match->cp_text[i]); xfree(match->cp_text[i]);
free(match); xfree(match);
} while (compl_curr_match != NULL && compl_curr_match != compl_first_match); } while (compl_curr_match != NULL && compl_curr_match != compl_first_match);
compl_first_match = compl_curr_match = NULL; compl_first_match = compl_curr_match = NULL;
compl_shown_match = NULL; compl_shown_match = NULL;
@ -2721,12 +2721,12 @@ static void ins_compl_clear(void)
compl_cont_status = 0; compl_cont_status = 0;
compl_started = FALSE; compl_started = FALSE;
compl_matches = 0; compl_matches = 0;
free(compl_pattern); xfree(compl_pattern);
compl_pattern = NULL; compl_pattern = NULL;
free(compl_leader); xfree(compl_leader);
compl_leader = NULL; compl_leader = NULL;
edit_submode_extra = NULL; edit_submode_extra = NULL;
free(compl_orig_text); xfree(compl_orig_text);
compl_orig_text = NULL; compl_orig_text = NULL;
compl_enter_selects = FALSE; compl_enter_selects = FALSE;
} }
@ -2767,7 +2767,7 @@ static int ins_compl_bs(void)
|| ins_compl_need_restart()) || ins_compl_need_restart())
ins_compl_restart(); ins_compl_restart();
free(compl_leader); xfree(compl_leader);
compl_leader = vim_strnsave(line + compl_col, (int)(p - line) - compl_col); compl_leader = vim_strnsave(line + compl_col, (int)(p - line) - compl_col);
ins_compl_new_leader(); ins_compl_new_leader();
if (compl_shown_match != NULL) if (compl_shown_match != NULL)
@ -2871,7 +2871,7 @@ static void ins_compl_addleader(int c)
* cursor doesn't point original position, changing compl_leader would * cursor doesn't point original position, changing compl_leader would
* break redo. */ * break redo. */
if (!compl_opt_refresh_always) { if (!compl_opt_refresh_always) {
free(compl_leader); xfree(compl_leader);
compl_leader = vim_strnsave(get_cursor_line_ptr() + compl_col, compl_leader = vim_strnsave(get_cursor_line_ptr() + compl_col,
(int)(curwin->w_cursor.col - compl_col)); (int)(curwin->w_cursor.col - compl_col));
ins_compl_new_leader(); ins_compl_new_leader();
@ -2898,7 +2898,7 @@ static void ins_compl_set_original_text(char_u *str)
{ {
/* Replace the original text entry. */ /* Replace the original text entry. */
if (compl_first_match->cp_flags & ORIGINAL_TEXT) { /* safety check */ if (compl_first_match->cp_flags & ORIGINAL_TEXT) { /* safety check */
free(compl_first_match->cp_str); xfree(compl_first_match->cp_str);
compl_first_match->cp_str = vim_strsave(str); compl_first_match->cp_str = vim_strsave(str);
} }
} }
@ -4449,13 +4449,13 @@ static int ins_complete(int c)
ins_compl_fixRedoBufForLeader(NULL); ins_compl_fixRedoBufForLeader(NULL);
/* Always add completion for the original text. */ /* Always add completion for the original text. */
free(compl_orig_text); xfree(compl_orig_text);
compl_orig_text = vim_strnsave(line + compl_col, compl_length); compl_orig_text = vim_strnsave(line + compl_col, compl_length);
if (ins_compl_add(compl_orig_text, -1, p_ic, NULL, NULL, 0, if (ins_compl_add(compl_orig_text, -1, p_ic, NULL, NULL, 0,
ORIGINAL_TEXT, FALSE) != OK) { ORIGINAL_TEXT, FALSE) != OK) {
free(compl_pattern); xfree(compl_pattern);
compl_pattern = NULL; compl_pattern = NULL;
free(compl_orig_text); xfree(compl_orig_text);
compl_orig_text = NULL; compl_orig_text = NULL;
return FAIL; return FAIL;
} }
@ -5326,7 +5326,7 @@ internal_format (
* moved, now we re-insert it into the new line. * moved, now we re-insert it into the new line.
*/ */
ins_bytes(saved_text); ins_bytes(saved_text);
free(saved_text); xfree(saved_text);
} else { } else {
/* /*
* Check if cursor is not past the NUL off the line, cindent * Check if cursor is not past the NUL off the line, cindent
@ -5661,11 +5661,11 @@ stop_insert (
ptr = get_inserted(); ptr = get_inserted();
if (did_restart_edit == 0 || (ptr != NULL if (did_restart_edit == 0 || (ptr != NULL
&& (int)STRLEN(ptr) > new_insert_skip)) { && (int)STRLEN(ptr) > new_insert_skip)) {
free(last_insert); xfree(last_insert);
last_insert = ptr; last_insert = ptr;
last_insert_skip = new_insert_skip; last_insert_skip = new_insert_skip;
} else } else
free(ptr); xfree(ptr);
if (!arrow_used && end_insert_pos != NULL) { if (!arrow_used && end_insert_pos != NULL) {
/* Auto-format now. It may seem strange to do this when stopping an /* Auto-format now. It may seem strange to do this when stopping an
@ -5770,7 +5770,7 @@ void set_last_insert(int c)
{ {
char_u *s; char_u *s;
free(last_insert); xfree(last_insert);
last_insert = xmalloc(MB_MAXBYTES * 3 + 5); last_insert = xmalloc(MB_MAXBYTES * 3 + 5);
s = last_insert; s = last_insert;
/* Use the CTRL-V only when entering a special char */ /* Use the CTRL-V only when entering a special char */
@ -5785,9 +5785,9 @@ void set_last_insert(int c)
#if defined(EXITFREE) #if defined(EXITFREE)
void free_last_insert(void) void free_last_insert(void)
{ {
free(last_insert); xfree(last_insert);
last_insert = NULL; last_insert = NULL;
free(compl_orig_text); xfree(compl_orig_text);
compl_orig_text = NULL; compl_orig_text = NULL;
} }
@ -6307,7 +6307,7 @@ static void mb_replace_pop_ins(int cc)
*/ */
static void replace_flush(void) static void replace_flush(void)
{ {
free(replace_stack); xfree(replace_stack);
replace_stack = NULL; replace_stack = NULL;
replace_stack_len = 0; replace_stack_len = 0;
replace_stack_nr = 0; replace_stack_nr = 0;
@ -7966,7 +7966,7 @@ static int ins_tab(void)
} }
if (State & VREPLACE_FLAG) if (State & VREPLACE_FLAG)
free(saved_line); xfree(saved_line);
curwin->w_p_list = save_list; curwin->w_p_list = save_list;
} }

File diff suppressed because it is too large Load Diff

View File

@ -533,9 +533,9 @@ void ex_sort(exarg_T *eap)
beginline(BL_WHITE | BL_FIX); beginline(BL_WHITE | BL_FIX);
sortend: sortend:
free(nrs); xfree(nrs);
free(sortbuf1); xfree(sortbuf1);
free(sortbuf2); xfree(sortbuf2);
vim_regfree(regmatch.regprog); vim_regfree(regmatch.regprog);
if (got_int) if (got_int)
EMSG(_(e_interr)); EMSG(_(e_interr));
@ -698,7 +698,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
for (extra = 0, l = line1; l <= line2; l++) { for (extra = 0, l = line1; l <= line2; l++) {
str = vim_strsave(ml_get(l + extra)); str = vim_strsave(ml_get(l + extra));
ml_append(dest + l - line1, str, (colnr_T)0, FALSE); ml_append(dest + l - line1, str, (colnr_T)0, FALSE);
free(str); xfree(str);
if (dest < line1) if (dest < line1)
extra++; extra++;
} }
@ -804,7 +804,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n)
* ml_append() */ * ml_append() */
p = vim_strsave(ml_get(line1)); p = vim_strsave(ml_get(line1));
ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE);
free(p); xfree(p);
/* situation 2: skip already copied lines */ /* situation 2: skip already copied lines */
if (line1 == n) if (line1 == n)
@ -827,7 +827,7 @@ static char_u *prevcmd = NULL; /* the previous command */
#if defined(EXITFREE) #if defined(EXITFREE)
void free_prev_shellcmd(void) void free_prev_shellcmd(void)
{ {
free(prevcmd); xfree(prevcmd);
} }
#endif #endif
@ -878,7 +878,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out)
if (ins_prevcmd) { if (ins_prevcmd) {
if (prevcmd == NULL) { if (prevcmd == NULL) {
EMSG(_(e_noprev)); EMSG(_(e_noprev));
free(newcmd); xfree(newcmd);
return; return;
} }
len += (int)STRLEN(prevcmd); len += (int)STRLEN(prevcmd);
@ -891,7 +891,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out)
STRCAT(t, prevcmd); STRCAT(t, prevcmd);
p = t + STRLEN(t); p = t + STRLEN(t);
STRCAT(t, trailarg); STRCAT(t, trailarg);
free(newcmd); xfree(newcmd);
newcmd = t; newcmd = t;
/* /*
@ -914,7 +914,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out)
} }
} while (trailarg != NULL); } while (trailarg != NULL);
free(prevcmd); xfree(prevcmd);
prevcmd = newcmd; prevcmd = newcmd;
if (bangredo) { /* put cmd in redo buffer for ! command */ if (bangredo) { /* put cmd in redo buffer for ! command */
@ -924,7 +924,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out)
char_u *cmd = vim_strsave_escaped(prevcmd, (char_u *)"%#"); char_u *cmd = vim_strsave_escaped(prevcmd, (char_u *)"%#");
AppendToRedobuffLit(cmd, -1); AppendToRedobuffLit(cmd, -1);
free(cmd); xfree(cmd);
AppendToRedobuff((char_u *)"\n"); AppendToRedobuff((char_u *)"\n");
bangredo = FALSE; bangredo = FALSE;
} }
@ -955,7 +955,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out)
apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, FALSE, curbuf);
} }
if (free_newcmd) if (free_newcmd)
free(newcmd); xfree(newcmd);
} }
/* /*
@ -1076,7 +1076,7 @@ do_filter (
if (do_out) { if (do_out) {
if (u_save((linenr_T)(line2), (linenr_T)(line2 + 1)) == FAIL) { if (u_save((linenr_T)(line2), (linenr_T)(line2 + 1)) == FAIL) {
free(cmd_buf); xfree(cmd_buf);
goto error; goto error;
} }
redraw_curbuf_later(VALID); redraw_curbuf_later(VALID);
@ -1100,7 +1100,7 @@ do_filter (
redraw_later_clear(); redraw_later_clear();
wait_return(FALSE); wait_return(FALSE);
} }
free(cmd_buf); xfree(cmd_buf);
did_check_timestamps = FALSE; did_check_timestamps = FALSE;
need_check_timestamps = TRUE; need_check_timestamps = TRUE;
@ -1197,8 +1197,8 @@ filterend:
os_remove((char *)itmp); os_remove((char *)itmp);
if (otmp != NULL) if (otmp != NULL)
os_remove((char *)otmp); os_remove((char *)otmp);
free(itmp); xfree(itmp);
free(otmp); xfree(otmp);
} }
/* /*
@ -1448,7 +1448,7 @@ read_viminfo (
verbose_leave(); verbose_leave();
} }
free(fname); xfree(fname);
if (fp == NULL) if (fp == NULL)
return FAIL; return FAIL;
@ -1550,7 +1550,7 @@ void write_viminfo(char_u *file, int forceit)
* write the viminfo file then. * write the viminfo file then.
*/ */
if (*wp == 'a') { if (*wp == 'a') {
free(tempname); xfree(tempname);
tempname = NULL; tempname = NULL;
break; break;
} }
@ -1586,7 +1586,7 @@ void write_viminfo(char_u *file, int forceit)
* "normal" temp file. * "normal" temp file.
*/ */
if (fp_out == NULL) { if (fp_out == NULL) {
free(tempname); xfree(tempname);
if ((tempname = vim_tempname()) != NULL) if ((tempname = vim_tempname()) != NULL)
fp_out = mch_fopen((char *)tempname, WRITEBIN); fp_out = mch_fopen((char *)tempname, WRITEBIN);
} }
@ -1639,8 +1639,8 @@ void write_viminfo(char_u *file, int forceit)
} }
end: end:
free(fname); xfree(fname);
free(tempname); xfree(tempname);
} }
/* /*
@ -1721,7 +1721,7 @@ static void do_viminfo(FILE *fp_in, FILE *fp_out, int flags)
&& (flags & (VIF_WANT_MARKS | VIF_GET_OLDFILES | VIF_FORCEIT))) && (flags & (VIF_WANT_MARKS | VIF_GET_OLDFILES | VIF_FORCEIT)))
copy_viminfo_marks(&vir, fp_out, count, eof, flags); copy_viminfo_marks(&vir, fp_out, count, eof, flags);
free(vir.vir_line); xfree(vir.vir_line);
if (vir.vir_conv.vc_type != CONV_NONE) if (vir.vir_conv.vc_type != CONV_NONE)
convert_setup(&vir.vir_conv, NULL, NULL); convert_setup(&vir.vir_conv, NULL, NULL);
} }
@ -1886,7 +1886,7 @@ viminfo_readstring (
if (convert && virp->vir_conv.vc_type != CONV_NONE && *retval != NUL) { if (convert && virp->vir_conv.vc_type != CONV_NONE && *retval != NUL) {
d = string_convert(&virp->vir_conv, retval, NULL); d = string_convert(&virp->vir_conv, retval, NULL);
if (d != NULL) { if (d != NULL) {
free(retval); xfree(retval);
retval = d; retval = d;
} }
} }
@ -2000,8 +2000,8 @@ int rename_buffer(char_u *new_fname)
if (buf != NULL && !cmdmod.keepalt) if (buf != NULL && !cmdmod.keepalt)
curwin->w_alt_fnum = buf->b_fnum; curwin->w_alt_fnum = buf->b_fnum;
} }
free(fname); xfree(fname);
free(sfname); xfree(sfname);
apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf);
/* Change directories when the 'acd' option is set. */ /* Change directories when the 'acd' option is set. */
do_autochdir(); do_autochdir();
@ -2206,7 +2206,7 @@ int do_write(exarg_T *eap)
} }
theend: theend:
free(free_fname); xfree(free_fname);
return retval; return retval;
} }
@ -2279,7 +2279,7 @@ check_overwrite (
copy_option_part(&p, dir, MAXPATHL, ","); copy_option_part(&p, dir, MAXPATHL, ",");
} }
swapname = makeswapname(fname, ffname, curbuf, dir); swapname = makeswapname(fname, ffname, curbuf, dir);
free(dir); xfree(dir);
if (os_file_exists(swapname)) { if (os_file_exists(swapname)) {
if (p_confirm || cmdmod.confirm) { if (p_confirm || cmdmod.confirm) {
char_u buff[DIALOG_MSG_SIZE]; char_u buff[DIALOG_MSG_SIZE];
@ -2289,18 +2289,18 @@ check_overwrite (
swapname); swapname);
if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2)
!= VIM_YES) { != VIM_YES) {
free(swapname); xfree(swapname);
return FAIL; return FAIL;
} }
eap->forceit = TRUE; eap->forceit = TRUE;
} else { } else {
EMSG2(_("E768: Swap file exists: %s (:silent! overrides)"), EMSG2(_("E768: Swap file exists: %s (:silent! overrides)"),
swapname); swapname);
free(swapname); xfree(swapname);
return FAIL; return FAIL;
} }
} }
free(swapname); xfree(swapname);
} }
} }
return OK; return OK;
@ -2486,7 +2486,7 @@ int getfile(int fnum, char_u *ffname, char_u *sfname, int setpm, linenr_T lnum,
retval = 1; /* error encountered */ retval = 1; /* error encountered */
theend: theend:
free(free_me); xfree(free_me);
return retval; return retval;
} }
@ -2623,7 +2623,7 @@ do_ecmd (
} }
set_vim_var_string(VV_SWAPCOMMAND, p, -1); set_vim_var_string(VV_SWAPCOMMAND, p, -1);
did_set_swapcommand = TRUE; did_set_swapcommand = TRUE;
free(p); xfree(p);
} }
/* /*
@ -2712,7 +2712,7 @@ do_ecmd (
goto theend; goto theend;
} }
if (aborting()) { /* autocmds may abort script processing */ if (aborting()) { /* autocmds may abort script processing */
free(new_name); xfree(new_name);
goto theend; goto theend;
} }
if (buf == curbuf) /* already in new buffer */ if (buf == curbuf) /* already in new buffer */
@ -2737,7 +2737,7 @@ do_ecmd (
} }
if (aborting()) { /* autocmds may abort script processing */ if (aborting()) { /* autocmds may abort script processing */
free(new_name); xfree(new_name);
goto theend; goto theend;
} }
/* Be careful again, like above. */ /* Be careful again, like above. */
@ -2775,7 +2775,7 @@ do_ecmd (
did_get_winopts = TRUE; did_get_winopts = TRUE;
} }
free(new_name); xfree(new_name);
au_new_curbuf = NULL; au_new_curbuf = NULL;
} else } else
++curbuf->b_nwindows; ++curbuf->b_nwindows;
@ -2849,7 +2849,7 @@ do_ecmd (
delbuf_msg(new_name); /* frees new_name */ delbuf_msg(new_name); /* frees new_name */
goto theend; goto theend;
} }
free(new_name); xfree(new_name);
/* If autocommands change buffers under our fingers, forget about /* If autocommands change buffers under our fingers, forget about
* re-editing the file. Should do the buf_clear_file(), but perhaps * re-editing the file. Should do the buf_clear_file(), but perhaps
@ -3040,7 +3040,7 @@ do_ecmd (
theend: theend:
if (did_set_swapcommand) if (did_set_swapcommand)
set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); set_vim_var_string(VV_SWAPCOMMAND, NULL, -1);
free(free_fname); xfree(free_fname);
return retval; return retval;
} }
@ -3048,7 +3048,7 @@ static void delbuf_msg(char_u *name)
{ {
EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"), EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"),
name == NULL ? (char_u *)"" : name); name == NULL ? (char_u *)"" : name);
free(name); xfree(name);
au_new_curbuf = NULL; au_new_curbuf = NULL;
} }
@ -3140,7 +3140,7 @@ void ex_append(exarg_T *eap)
if ((p[0] == '.' && p[1] == NUL) if ((p[0] == '.' && p[1] == NUL)
|| (!did_undo && u_save(lnum, lnum + 1 + (empty ? 1 : 0)) || (!did_undo && u_save(lnum, lnum + 1 + (empty ? 1 : 0))
== FAIL)) { == FAIL)) {
free(theline); xfree(theline);
break; break;
} }
@ -3152,7 +3152,7 @@ void ex_append(exarg_T *eap)
ml_append(lnum, theline, (colnr_T)0, FALSE); ml_append(lnum, theline, (colnr_T)0, FALSE);
appended_lines_mark(lnum, 1L); appended_lines_mark(lnum, 1L);
free(theline); xfree(theline);
++lnum; ++lnum;
if (empty) { if (empty) {
@ -3481,7 +3481,7 @@ void do_sub(exarg_T *eap)
} }
sub = old_sub; sub = old_sub;
} else { } else {
free(old_sub); xfree(old_sub);
old_sub = vim_strsave(sub); old_sub = vim_strsave(sub);
} }
} }
@ -3742,7 +3742,7 @@ void do_sub(exarg_T *eap)
lnum += regmatch.startpos[0].lnum; lnum += regmatch.startpos[0].lnum;
sub_firstlnum += regmatch.startpos[0].lnum; sub_firstlnum += regmatch.startpos[0].lnum;
nmatch -= regmatch.startpos[0].lnum; nmatch -= regmatch.startpos[0].lnum;
free(sub_firstline); xfree(sub_firstline);
sub_firstline = NULL; sub_firstline = NULL;
} }
@ -3846,7 +3846,7 @@ void do_sub(exarg_T *eap)
resp = getexmodeline('?', NULL, 0); resp = getexmodeline('?', NULL, 0);
if (resp != NULL) { if (resp != NULL) {
typed = *resp; typed = *resp;
free(resp); xfree(resp);
} }
} else { } else {
char_u *orig_line = NULL; char_u *orig_line = NULL;
@ -4061,7 +4061,7 @@ void do_sub(exarg_T *eap)
* line and continue in that one. */ * line and continue in that one. */
if (nmatch > 1) { if (nmatch > 1) {
sub_firstlnum += nmatch - 1; sub_firstlnum += nmatch - 1;
free(sub_firstline); xfree(sub_firstline);
sub_firstline = vim_strsave(ml_get(sub_firstlnum)); sub_firstline = vim_strsave(ml_get(sub_firstlnum));
/* When going beyond the last line, stop substituting. */ /* When going beyond the last line, stop substituting. */
if (sub_firstlnum <= line2) if (sub_firstlnum <= line2)
@ -4076,7 +4076,7 @@ void do_sub(exarg_T *eap)
if (skip_match) { if (skip_match) {
/* Already hit end of the buffer, sub_firstlnum is one /* Already hit end of the buffer, sub_firstlnum is one
* less than what it ought to be. */ * less than what it ought to be. */
free(sub_firstline); xfree(sub_firstline);
sub_firstline = vim_strsave((char_u *)""); sub_firstline = vim_strsave((char_u *)"");
copycol = 0; copycol = 0;
} }
@ -4204,7 +4204,7 @@ skip:
} }
sub_firstlnum = lnum; sub_firstlnum = lnum;
free(sub_firstline); /* free the temp buffer */ xfree(sub_firstline); /* free the temp buffer */
sub_firstline = new_start; sub_firstline = new_start;
new_start = NULL; new_start = NULL;
matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol;
@ -4234,8 +4234,8 @@ skip:
if (did_sub) if (did_sub)
++sub_nlines; ++sub_nlines;
free(new_start); /* for when substitute was cancelled */ xfree(new_start); /* for when substitute was cancelled */
free(sub_firstline); /* free the copy of the original line */ xfree(sub_firstline); /* free the copy of the original line */
sub_firstline = NULL; sub_firstline = NULL;
} }
@ -4250,7 +4250,7 @@ skip:
changed_lines(first_line, 0, last_line - i, i); changed_lines(first_line, 0, last_line - i, i);
} }
free(sub_firstline); /* may have to free allocated copy of the line */ xfree(sub_firstline); /* may have to free allocated copy of the line */
/* ":s/pat//n" doesn't move the cursor */ /* ":s/pat//n" doesn't move the cursor */
if (do_count) if (do_count)
@ -4510,7 +4510,7 @@ void global_exe(char_u *cmd)
int read_viminfo_sub_string(vir_T *virp, int force) int read_viminfo_sub_string(vir_T *virp, int force)
{ {
if (force) if (force)
free(old_sub); xfree(old_sub);
if (force || old_sub == NULL) if (force || old_sub == NULL)
old_sub = viminfo_readstring(virp, 1, TRUE); old_sub = viminfo_readstring(virp, 1, TRUE);
return viminfo_readline(virp); return viminfo_readline(virp);
@ -4527,7 +4527,7 @@ void write_viminfo_sub_string(FILE *fp)
#if defined(EXITFREE) #if defined(EXITFREE)
void free_old_sub(void) void free_old_sub(void)
{ {
free(old_sub); xfree(old_sub);
} }
#endif #endif
@ -4739,7 +4739,7 @@ void ex_help(exarg_T *eap)
curwin->w_alt_fnum = alt_fnum; curwin->w_alt_fnum = alt_fnum;
erret: erret:
free(tag); xfree(tag);
} }
@ -5003,7 +5003,7 @@ int find_help_tags(char_u *arg, int *num_matches, char_u ***matches, int keep_la
sizeof(char_u *), help_compare); sizeof(char_u *), help_compare);
/* Delete more than TAG_MANY to reduce the size of the listing. */ /* Delete more than TAG_MANY to reduce the size of the listing. */
while (*num_matches > TAG_MANY) while (*num_matches > TAG_MANY)
free((*matches)[--*num_matches]); xfree((*matches)[--*num_matches]);
} }
return OK; return OK;
} }
@ -5165,7 +5165,7 @@ void fix_help_buffer(void)
if (fnamecmp(e1, ".txt") != 0 if (fnamecmp(e1, ".txt") != 0
&& fnamecmp(e1, fname + 4) != 0) { && fnamecmp(e1, fname + 4) != 0) {
/* Not .txt and not .abx, remove it. */ /* Not .txt and not .abx, remove it. */
free(fnames[i1]); xfree(fnames[i1]);
fnames[i1] = NULL; fnames[i1] = NULL;
continue; continue;
} }
@ -5174,7 +5174,7 @@ void fix_help_buffer(void)
if (fnamecmp(e1, ".txt") == 0 if (fnamecmp(e1, ".txt") == 0
&& fnamecmp(e2, fname + 4) == 0) { && fnamecmp(e2, fname + 4) == 0) {
/* use .abx instead of .txt */ /* use .abx instead of .txt */
free(fnames[i1]); xfree(fnames[i1]);
fnames[i1] = NULL; fnames[i1] = NULL;
} }
} }
@ -5234,7 +5234,7 @@ void fix_help_buffer(void)
ml_append(lnum, cp, (colnr_T)0, FALSE); ml_append(lnum, cp, (colnr_T)0, FALSE);
if (cp != IObuff) if (cp != IObuff)
free(cp); xfree(cp);
++lnum; ++lnum;
} }
fclose(fd); fclose(fd);
@ -5243,7 +5243,7 @@ void fix_help_buffer(void)
} }
} }
if (mustfree) if (mustfree)
free(rt); xfree(rt);
} }
break; break;
} }
@ -5310,7 +5310,7 @@ void ex_helptags(exarg_T *eap)
EW_FILE|EW_SILENT) == FAIL EW_FILE|EW_SILENT) == FAIL
|| filecount == 0) { || filecount == 0) {
EMSG2("E151: No match: %s", NameBuff); EMSG2("E151: No match: %s", NameBuff);
free(dirname); xfree(dirname);
return; return;
} }
@ -5372,7 +5372,7 @@ void ex_helptags(exarg_T *eap)
ga_clear(&ga); ga_clear(&ga);
FreeWild(filecount, files); FreeWild(filecount, files);
free(dirname); xfree(dirname);
} }
static void static void
@ -5722,7 +5722,7 @@ void ex_sign(exarg_T *eap)
next_sign_typenr = 1; next_sign_typenr = 1;
if (next_sign_typenr == start) if (next_sign_typenr == start)
{ {
free(sp); xfree(sp);
EMSG(_("E612: Too many signs defined")); EMSG(_("E612: Too many signs defined"));
return; return;
} }
@ -5755,7 +5755,7 @@ void ex_sign(exarg_T *eap)
if (STRNCMP(arg, "icon=", 5) == 0) if (STRNCMP(arg, "icon=", 5) == 0)
{ {
arg += 5; arg += 5;
free(sp->sn_icon); xfree(sp->sn_icon);
sp->sn_icon = vim_strnsave(arg, (int)(p - arg)); sp->sn_icon = vim_strnsave(arg, (int)(p - arg));
backslash_halve(sp->sn_icon); backslash_halve(sp->sn_icon);
} }
@ -5794,7 +5794,7 @@ void ex_sign(exarg_T *eap)
return; return;
} }
free(sp->sn_text); xfree(sp->sn_text);
/* Allocate one byte more if we need to pad up /* Allocate one byte more if we need to pad up
* with a space. */ * with a space. */
len = (int)(p - arg + ((cells == 1) ? 1 : 0)); len = (int)(p - arg + ((cells == 1) ? 1 : 0));
@ -5983,7 +5983,7 @@ void ex_sign(exarg_T *eap)
sprintf((char *)cmd, "e +%" PRId64 " %s", sprintf((char *)cmd, "e +%" PRId64 " %s",
(int64_t)lnum, buf->b_fname); (int64_t)lnum, buf->b_fname);
do_cmdline_cmd(cmd); do_cmdline_cmd(cmd);
free(cmd); xfree(cmd);
} }
foldOpenCursor(); foldOpenCursor();
@ -6076,14 +6076,14 @@ static void sign_list_defined(sign_T *sp)
*/ */
static void sign_undefine(sign_T *sp, sign_T *sp_prev) static void sign_undefine(sign_T *sp, sign_T *sp_prev)
{ {
free(sp->sn_name); xfree(sp->sn_name);
free(sp->sn_icon); xfree(sp->sn_icon);
free(sp->sn_text); xfree(sp->sn_text);
if (sp_prev == NULL) if (sp_prev == NULL)
first_sign = sp->sn_next; first_sign = sp->sn_next;
else else
sp_prev->sn_next = sp->sn_next; sp_prev->sn_next = sp->sn_next;
free(sp); xfree(sp);
} }
/* /*

View File

@ -278,11 +278,11 @@ void do_debug(char_u *cmd)
DOCMD_VERBOSE|DOCMD_EXCRESET); DOCMD_VERBOSE|DOCMD_EXCRESET);
debug_break_level = n; debug_break_level = n;
free(cmdline); xfree(cmdline);
} }
lines_left = Rows - 1; lines_left = Rows - 1;
} }
free(cmdline); xfree(cmdline);
--RedrawingDisabled; --RedrawingDisabled;
--no_wait_return; --no_wait_return;
@ -491,12 +491,12 @@ dbg_parsearg (
if (q == NULL) if (q == NULL)
return FAIL; return FAIL;
p = expand_env_save(q); p = expand_env_save(q);
free(q); xfree(q);
if (p == NULL) if (p == NULL)
return FAIL; return FAIL;
if (*p != '*') { if (*p != '*') {
bp->dbg_name = fix_fname(p); bp->dbg_name = fix_fname(p);
free(p); xfree(p);
} else } else
bp->dbg_name = p; bp->dbg_name = p;
} }
@ -526,10 +526,10 @@ void ex_breakadd(exarg_T *eap)
pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE); pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE);
if (pat != NULL) { if (pat != NULL) {
bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING); bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
free(pat); xfree(pat);
} }
if (pat == NULL || bp->dbg_prog == NULL) if (pat == NULL || bp->dbg_prog == NULL)
free(bp->dbg_name); xfree(bp->dbg_name);
else { else {
if (bp->dbg_lnum == 0) /* default line number is 1 */ if (bp->dbg_lnum == 0) /* default line number is 1 */
bp->dbg_lnum = 1; bp->dbg_lnum = 1;
@ -598,14 +598,14 @@ void ex_breakdel(exarg_T *eap)
best_lnum = bpi->dbg_lnum; best_lnum = bpi->dbg_lnum;
} }
} }
free(bp->dbg_name); xfree(bp->dbg_name);
} }
if (todel < 0) if (todel < 0)
EMSG2(_("E161: Breakpoint not found: %s"), eap->arg); EMSG2(_("E161: Breakpoint not found: %s"), eap->arg);
else { else {
while (!GA_EMPTY(gap)) { while (!GA_EMPTY(gap)) {
free(DEBUGGY(gap, todel).dbg_name); xfree(DEBUGGY(gap, todel).dbg_name);
vim_regfree(DEBUGGY(gap, todel).dbg_prog); vim_regfree(DEBUGGY(gap, todel).dbg_prog);
--gap->ga_len; --gap->ga_len;
if (todel < gap->ga_len) if (todel < gap->ga_len)
@ -727,7 +727,7 @@ debuggy_find (
} }
} }
if (name != fname) if (name != fname)
free(name); xfree(name);
return lnum; return lnum;
} }
@ -759,7 +759,7 @@ void ex_profile(exarg_T *eap)
e = skipwhite(e); e = skipwhite(e);
if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL) { if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL) {
free(profile_fname); xfree(profile_fname);
profile_fname = expand_env_save_opt(e, true); profile_fname = expand_env_save_opt(e, true);
do_profiling = PROF_YES; do_profiling = PROF_YES;
profile_set_wait(profile_zero()); profile_set_wait(profile_zero());
@ -1293,7 +1293,7 @@ buf_found:
set_curbuf(buf, DOBUF_GOTO); set_curbuf(buf, DOBUF_GOTO);
theend: theend:
free(bufnrs); xfree(bufnrs);
return ret; return ret;
} }
@ -1450,7 +1450,7 @@ do_arglist (
break; break;
regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0);
if (regmatch.regprog == NULL) { if (regmatch.regprog == NULL) {
free(p); xfree(p);
break; break;
} }
@ -1459,7 +1459,7 @@ do_arglist (
if (vim_regexec(&regmatch, alist_name(&ARGLIST[match]), if (vim_regexec(&regmatch, alist_name(&ARGLIST[match]),
(colnr_T)0)) { (colnr_T)0)) {
didone = TRUE; didone = TRUE;
free(ARGLIST[match].ae_fname); xfree(ARGLIST[match].ae_fname);
memmove(ARGLIST + match, ARGLIST + match + 1, memmove(ARGLIST + match, ARGLIST + match + 1,
(ARGCOUNT - match - 1) * sizeof(aentry_T)); (ARGCOUNT - match - 1) * sizeof(aentry_T));
--ALIST(curwin)->al_ga.ga_len; --ALIST(curwin)->al_ga.ga_len;
@ -1469,7 +1469,7 @@ do_arglist (
} }
vim_regfree(regmatch.regprog); vim_regfree(regmatch.regprog);
free(p); xfree(p);
if (!didone) if (!didone)
EMSG2(_(e_nomatch2), ((char_u **)new_ga.ga_data)[i]); EMSG2(_(e_nomatch2), ((char_u **)new_ga.ga_data)[i]);
} }
@ -1487,7 +1487,7 @@ do_arglist (
if (what == AL_ADD) { if (what == AL_ADD) {
(void)alist_add_list(exp_count, exp_files, after); (void)alist_add_list(exp_count, exp_files, after);
free(exp_files); xfree(exp_files);
} else /* what == AL_SET */ } else /* what == AL_SET */
alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0); alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0);
} }
@ -1683,7 +1683,7 @@ void do_argfile(exarg_T *eap, int argn)
if (P_HID(curbuf)) { if (P_HID(curbuf)) {
p = fix_fname(alist_name(&ARGLIST[argn])); p = fix_fname(alist_name(&ARGLIST[argn]));
other = otherfile(p); other = otherfile(p);
free(p); xfree(p);
} }
if ((!P_HID(curbuf) || !other) if ((!P_HID(curbuf) || !other)
&& check_changed(curbuf, CCGD_AW && check_changed(curbuf, CCGD_AW
@ -1793,7 +1793,7 @@ void ex_argdelete(exarg_T *eap)
EMSG(_(e_invarg)); EMSG(_(e_invarg));
else { else {
for (int i = eap->line1; i <= eap->line2; ++i) for (int i = eap->line1; i <= eap->line2; ++i)
free(ARGLIST[i - 1].ae_fname); xfree(ARGLIST[i - 1].ae_fname);
memmove(ARGLIST + eap->line1 - 1, ARGLIST + eap->line2, memmove(ARGLIST + eap->line1 - 1, ARGLIST + eap->line2,
(size_t)((ARGCOUNT - eap->line2) * sizeof(aentry_T))); (size_t)((ARGCOUNT - eap->line2) * sizeof(aentry_T)));
ALIST(curwin)->al_ga.ga_len -= n; ALIST(curwin)->al_ga.ga_len -= n;
@ -1858,7 +1858,7 @@ void ex_listdo(exarg_T *eap)
set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); set_option_value((char_u *)"shm", 0L, (char_u *)"", 0);
do_argfile(eap, i); do_argfile(eap, i);
set_option_value((char_u *)"shm", 0L, p_shm_save, 0); set_option_value((char_u *)"shm", 0L, p_shm_save, 0);
free(p_shm_save); xfree(p_shm_save);
} }
if (curwin->w_arg_idx != i) if (curwin->w_arg_idx != i)
break; break;
@ -1915,7 +1915,7 @@ void ex_listdo(exarg_T *eap)
set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); set_option_value((char_u *)"shm", 0L, (char_u *)"", 0);
goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum);
set_option_value((char_u *)"shm", 0L, p_shm_save, 0); set_option_value((char_u *)"shm", 0L, p_shm_save, 0);
free(p_shm_save); xfree(p_shm_save);
/* If autocommands took us elsewhere, quit here */ /* If autocommands took us elsewhere, quit here */
if (curbuf->b_fnum != next_fnum) if (curbuf->b_fnum != next_fnum)
@ -2011,7 +2011,7 @@ void ex_compiler(exarg_T *eap)
sprintf((char *)buf, "compiler/%s.vim", eap->arg); sprintf((char *)buf, "compiler/%s.vim", eap->arg);
if (source_runtime(buf, TRUE) == FAIL) if (source_runtime(buf, TRUE) == FAIL)
EMSG2(_("E666: compiler not supported: %s"), eap->arg); EMSG2(_("E666: compiler not supported: %s"), eap->arg);
free(buf); xfree(buf);
do_cmdline_cmd((char_u *)":delcommand CompilerSet"); do_cmdline_cmd((char_u *)":delcommand CompilerSet");
@ -2025,7 +2025,7 @@ void ex_compiler(exarg_T *eap)
if (old_cur_comp != NULL) { if (old_cur_comp != NULL) {
set_internal_string_var((char_u *)"g:current_compiler", set_internal_string_var((char_u *)"g:current_compiler",
old_cur_comp); old_cur_comp);
free(old_cur_comp); xfree(old_cur_comp);
} else } else
do_unlet((char_u *)"g:current_compiler", TRUE); do_unlet((char_u *)"g:current_compiler", TRUE);
} }
@ -2135,8 +2135,8 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback,
} }
} }
} }
free(buf); xfree(buf);
free(rtp_copy); xfree(rtp_copy);
if (p_verbose > 0 && !did_one && name != NULL) { if (p_verbose > 0 && !did_one && name != NULL) {
verbose_enter(); verbose_enter();
smsg((char_u *)_("not found in 'runtimepath': \"%s\""), name); smsg((char_u *)_("not found in 'runtimepath': \"%s\""), name);
@ -2273,7 +2273,7 @@ do_source (
if (p == NULL) if (p == NULL)
return retval; return retval;
fname_exp = fix_fname(p); fname_exp = fix_fname(p);
free(p); xfree(p);
if (fname_exp == NULL) if (fname_exp == NULL)
return retval; return retval;
if (os_isdir(fname_exp)) { if (os_isdir(fname_exp)) {
@ -2391,7 +2391,7 @@ do_source (
p = string_convert(&cookie.conv, firstline + 3, NULL); p = string_convert(&cookie.conv, firstline + 3, NULL);
if (p == NULL) if (p == NULL)
p = vim_strsave(firstline + 3); p = vim_strsave(firstline + 3);
free(firstline); xfree(firstline);
firstline = p; firstline = p;
} }
@ -2518,12 +2518,12 @@ do_source (
if (l_do_profiling == PROF_YES) if (l_do_profiling == PROF_YES)
prof_child_exit(&wait_start); /* leaving a child now */ prof_child_exit(&wait_start); /* leaving a child now */
fclose(cookie.fp); fclose(cookie.fp);
free(cookie.nextline); xfree(cookie.nextline);
free(firstline); xfree(firstline);
convert_setup(&cookie.conv, NULL, NULL); convert_setup(&cookie.conv, NULL, NULL);
theend: theend:
free(fname_exp); xfree(fname_exp);
return retval; return retval;
} }
@ -2577,7 +2577,7 @@ char_u *get_scriptname(scid_T id)
# if defined(EXITFREE) # if defined(EXITFREE)
void free_scriptnames() void free_scriptnames()
{ {
# define FREE_SCRIPTNAME(item) free((item)->sn_name) # define FREE_SCRIPTNAME(item) xfree((item)->sn_name)
GA_DEEP_CLEAR(&script_items, scriptitem_T, FREE_SCRIPTNAME); GA_DEEP_CLEAR(&script_items, scriptitem_T, FREE_SCRIPTNAME);
} }
# endif # endif
@ -2636,7 +2636,7 @@ char_u *getsourceline(int c, void *cookie, int indent)
ga_concat(&ga, line); ga_concat(&ga, line);
ga_concat(&ga, p + 1); ga_concat(&ga, p + 1);
for (;; ) { for (;; ) {
free(sp->nextline); xfree(sp->nextline);
sp->nextline = get_one_sourceline(sp); sp->nextline = get_one_sourceline(sp);
if (sp->nextline == NULL) if (sp->nextline == NULL)
break; break;
@ -2651,7 +2651,7 @@ char_u *getsourceline(int c, void *cookie, int indent)
ga_concat(&ga, p + 1); ga_concat(&ga, p + 1);
} }
ga_append(&ga, NUL); ga_append(&ga, NUL);
free(line); xfree(line);
line = ga.ga_data; line = ga.ga_data;
} }
} }
@ -2662,7 +2662,7 @@ char_u *getsourceline(int c, void *cookie, int indent)
/* Convert the encoding of the script line. */ /* Convert the encoding of the script line. */
s = string_convert(&sp->conv, line, NULL); s = string_convert(&sp->conv, line, NULL);
if (s != NULL) { if (s != NULL) {
free(line); xfree(line);
line = s; line = s;
} }
} }
@ -2771,7 +2771,7 @@ static char_u *get_one_sourceline(struct source_cookie *sp)
if (have_read) if (have_read)
return (char_u *)ga.ga_data; return (char_u *)ga.ga_data;
free(ga.ga_data); xfree(ga.ga_data);
return NULL; return NULL;
} }
@ -2874,7 +2874,7 @@ void ex_scriptencoding(exarg_T *eap)
convert_setup(&sp->conv, name, p_enc); convert_setup(&sp->conv, name, p_enc);
if (name != eap->arg) if (name != eap->arg)
free(name); xfree(name);
} }
/* /*
@ -3192,7 +3192,7 @@ static char_u **find_locales(void)
GA_APPEND(char_u *, &locales_ga, loc); GA_APPEND(char_u *, &locales_ga, loc);
loc = (char_u *)strtok(NULL, "\n"); loc = (char_u *)strtok(NULL, "\n");
} }
free(locale_a); xfree(locale_a);
// Guarantee that .ga_data is NULL terminated // Guarantee that .ga_data is NULL terminated
ga_grow(&locales_ga, 1); ga_grow(&locales_ga, 1);
((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL;
@ -3205,8 +3205,8 @@ void free_locales(void)
int i; int i;
if (locales != NULL) { if (locales != NULL) {
for (i = 0; locales[i] != NULL; i++) for (i = 0; locales[i] != NULL; i++)
free(locales[i]); xfree(locales[i]);
free(locales); xfree(locales);
locales = NULL; locales = NULL;
} }
} }
@ -3260,7 +3260,7 @@ static void script_host_execute(char *name, exarg_T *eap)
(void)eval_call_provider(name, "execute", args); (void)eval_call_provider(name, "execute", args);
} }
free(script); xfree(script);
} }
static void script_host_execute_file(char *name, exarg_T *eap) static void script_host_execute_file(char *name, exarg_T *eap)

View File

@ -104,7 +104,7 @@ typedef struct {
linenr_T lnum; /* sourcing_lnum of the line */ linenr_T lnum; /* sourcing_lnum of the line */
} wcmd_T; } wcmd_T;
#define FREE_WCMD(wcmd) free((wcmd)->line) #define FREE_WCMD(wcmd) xfree((wcmd)->line)
/* /*
* Structure used to store info for line position in a while or for loop. * Structure used to store info for line position in a while or for loop.
@ -458,7 +458,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline,
if (cstack.cs_looplevel > 0 && current_line < lines_ga.ga_len) { if (cstack.cs_looplevel > 0 && current_line < lines_ga.ga_len) {
/* Each '|' separated command is stored separately in lines_ga, to /* Each '|' separated command is stored separately in lines_ga, to
* be able to jump to it. Don't use next_cmdline now. */ * be able to jump to it. Don't use next_cmdline now. */
free(cmdline_copy); xfree(cmdline_copy);
cmdline_copy = NULL; cmdline_copy = NULL;
/* Check if a function has returned or, unless it has an unclosed /* Check if a function has returned or, unless it has an unclosed
@ -554,7 +554,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline,
* Keep the first typed line. Clear it when more lines are typed. * Keep the first typed line. Clear it when more lines are typed.
*/ */
if (flags & DOCMD_KEEPLINE) { if (flags & DOCMD_KEEPLINE) {
free(repeat_cmdline); xfree(repeat_cmdline);
if (count == 0) if (count == 0)
repeat_cmdline = vim_strsave(next_cmdline); repeat_cmdline = vim_strsave(next_cmdline);
else else
@ -628,7 +628,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline,
current_line = cmd_loop_cookie.current_line; current_line = cmd_loop_cookie.current_line;
if (next_cmdline == NULL) { if (next_cmdline == NULL) {
free(cmdline_copy); xfree(cmdline_copy);
cmdline_copy = NULL; cmdline_copy = NULL;
/* /*
* If the command was typed, remember it for the ':' register. * If the command was typed, remember it for the ':' register.
@ -636,7 +636,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline,
*/ */
if (getline_equal(fgetline, cookie, getexline) if (getline_equal(fgetline, cookie, getexline)
&& new_last_cmdline != NULL) { && new_last_cmdline != NULL) {
free(last_cmdline); xfree(last_cmdline);
last_cmdline = new_last_cmdline; last_cmdline = new_last_cmdline;
new_last_cmdline = NULL; new_last_cmdline = NULL;
} }
@ -777,7 +777,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline,
|| cstack.cs_idx >= 0 || cstack.cs_idx >= 0
|| (flags & DOCMD_REPEAT))); || (flags & DOCMD_REPEAT)));
free(cmdline_copy); xfree(cmdline_copy);
did_emsg_syntax = FALSE; did_emsg_syntax = FALSE;
GA_DEEP_CLEAR(&lines_ga, wcmd_T, FREE_WCMD); GA_DEEP_CLEAR(&lines_ga, wcmd_T, FREE_WCMD);
@ -875,15 +875,15 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline,
do { do {
next = messages->next; next = messages->next;
emsg(messages->msg); emsg(messages->msg);
free(messages->msg); xfree(messages->msg);
free(messages); xfree(messages);
messages = next; messages = next;
} while (messages != NULL); } while (messages != NULL);
} else if (p != NULL) { } else if (p != NULL) {
emsg(p); emsg(p);
free(p); xfree(p);
} }
free(sourcing_name); xfree(sourcing_name);
sourcing_name = saved_sourcing_name; sourcing_name = saved_sourcing_name;
sourcing_lnum = saved_sourcing_lnum; sourcing_lnum = saved_sourcing_lnum;
} }
@ -1459,7 +1459,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
} }
p = vim_strnsave(ea.cmd, p - ea.cmd); p = vim_strnsave(ea.cmd, p - ea.cmd);
int ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, TRUE, NULL); int ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, TRUE, NULL);
free(p); xfree(p);
if (ret && !aborting()) { if (ret && !aborting()) {
p = find_command(&ea, NULL); p = find_command(&ea, NULL);
} }
@ -3285,7 +3285,7 @@ static void ex_script_ni(exarg_T *eap)
if (!eap->skip) if (!eap->skip)
ex_ni(eap); ex_ni(eap);
else else
free(script_get(eap, eap->arg)); xfree(script_get(eap, eap->arg));
} }
/* /*
@ -3400,7 +3400,7 @@ static char_u *replace_makeprg(exarg_T *eap, char_u *p, char_u **cmdlinep)
msg_make(p); msg_make(p);
/* 'eap->cmd' is not set here, because it is not used at CMD_make */ /* 'eap->cmd' is not set here, because it is not used at CMD_make */
free(*cmdlinep); xfree(*cmdlinep);
*cmdlinep = new_cmdline; *cmdlinep = new_cmdline;
p = new_cmdline; p = new_cmdline;
} }
@ -3464,7 +3464,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
char_u *l = repl; char_u *l = repl;
repl = expand_env_save(repl); repl = expand_env_save(repl);
free(l); xfree(l);
} }
/* Need to escape white space et al. with a backslash. /* Need to escape white space et al. with a backslash.
@ -3500,7 +3500,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
for (l = repl; *l; ++l) for (l = repl; *l; ++l)
if (vim_strchr(ESCAPE_CHARS, *l) != NULL) { if (vim_strchr(ESCAPE_CHARS, *l) != NULL) {
l = vim_strsave_escaped(repl, ESCAPE_CHARS); l = vim_strsave_escaped(repl, ESCAPE_CHARS);
free(repl); xfree(repl);
repl = l; repl = l;
break; break;
} }
@ -3512,12 +3512,12 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
char_u *l; char_u *l;
l = vim_strsave_escaped(repl, (char_u *)"!"); l = vim_strsave_escaped(repl, (char_u *)"!");
free(repl); xfree(repl);
repl = l; repl = l;
} }
p = repl_cmdline(eap, p, srclen, repl, cmdlinep); p = repl_cmdline(eap, p, srclen, repl, cmdlinep);
free(repl); xfree(repl);
} }
/* /*
@ -3595,7 +3595,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
if (p != NULL) { if (p != NULL) {
(void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg), (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg),
p, cmdlinep); p, cmdlinep);
free(p); xfree(p);
} }
} }
} }
@ -3649,7 +3649,7 @@ static char_u *repl_cmdline(exarg_T *eap, char_u *src, int srclen, char_u *repl,
eap->arg = new_cmdline + (eap->arg - *cmdlinep); eap->arg = new_cmdline + (eap->arg - *cmdlinep);
if (eap->do_ecmd_cmd != NULL && eap->do_ecmd_cmd != dollar_command) if (eap->do_ecmd_cmd != NULL && eap->do_ecmd_cmd != dollar_command)
eap->do_ecmd_cmd = new_cmdline + (eap->do_ecmd_cmd - *cmdlinep); eap->do_ecmd_cmd = new_cmdline + (eap->do_ecmd_cmd - *cmdlinep);
free(*cmdlinep); xfree(*cmdlinep);
*cmdlinep = new_cmdline; *cmdlinep = new_cmdline;
return src; return src;
@ -4141,9 +4141,9 @@ static int uc_add_command(char_u *name, size_t name_len, char_u *rep,
goto fail; goto fail;
} }
free(cmd->uc_rep); xfree(cmd->uc_rep);
cmd->uc_rep = NULL; cmd->uc_rep = NULL;
free(cmd->uc_compl_arg); xfree(cmd->uc_compl_arg);
cmd->uc_compl_arg = NULL; cmd->uc_compl_arg = NULL;
break; break;
} }
@ -4177,8 +4177,8 @@ static int uc_add_command(char_u *name, size_t name_len, char_u *rep,
return OK; return OK;
fail: fail:
free(rep_buf); xfree(rep_buf);
free(compl_arg); xfree(compl_arg);
return FAIL; return FAIL;
} }
@ -4531,9 +4531,9 @@ void ex_comclear(exarg_T *eap)
} }
static void free_ucmd(ucmd_T* cmd) { static void free_ucmd(ucmd_T* cmd) {
free(cmd->uc_name); xfree(cmd->uc_name);
free(cmd->uc_rep); xfree(cmd->uc_rep);
free(cmd->uc_compl_arg); xfree(cmd->uc_compl_arg);
} }
/* /*
@ -4569,9 +4569,9 @@ static void ex_delcommand(exarg_T *eap)
return; return;
} }
free(cmd->uc_name); xfree(cmd->uc_name);
free(cmd->uc_rep); xfree(cmd->uc_rep);
free(cmd->uc_compl_arg); xfree(cmd->uc_compl_arg);
--gap->ga_len; --gap->ga_len;
@ -4937,8 +4937,8 @@ static void do_ucmd(exarg_T *eap)
(void)do_cmdline(buf, eap->getline, eap->cookie, (void)do_cmdline(buf, eap->getline, eap->cookie,
DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED); DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED);
current_SID = save_current_SID; current_SID = save_current_SID;
free(buf); xfree(buf);
free(split_buf); xfree(split_buf);
} }
static char_u *get_user_command_name(int idx) static char_u *get_user_command_name(int idx)
@ -5064,11 +5064,11 @@ static void ex_colorscheme(exarg_T *eap)
++emsg_off; ++emsg_off;
p = eval_to_string(expr, NULL, FALSE); p = eval_to_string(expr, NULL, FALSE);
--emsg_off; --emsg_off;
free(expr); xfree(expr);
if (p != NULL) { if (p != NULL) {
MSG(p); MSG(p);
free(p); xfree(p);
} else } else
MSG("default"); MSG("default");
} else if (load_colors(eap->arg) == FAIL) } else if (load_colors(eap->arg) == FAIL)
@ -5468,7 +5468,7 @@ static void ex_goto(exarg_T *eap)
*/ */
void alist_clear(alist_T *al) void alist_clear(alist_T *al)
{ {
# define FREE_AENTRY_FNAME(arg) free(arg->ae_fname) # define FREE_AENTRY_FNAME(arg) xfree(arg->ae_fname)
GA_DEEP_CLEAR(&al->al_ga, aentry_T, FREE_AENTRY_FNAME); GA_DEEP_CLEAR(&al->al_ga, aentry_T, FREE_AENTRY_FNAME);
} }
@ -5490,7 +5490,7 @@ void alist_unlink(alist_T *al)
{ {
if (al != &global_alist && --al->al_refcount <= 0) { if (al != &global_alist && --al->al_refcount <= 0) {
alist_clear(al); alist_clear(al);
free(al); xfree(al);
} }
} }
@ -5556,7 +5556,7 @@ void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum
/* When adding many buffers this can take a long time. Allow /* When adding many buffers this can take a long time. Allow
* interrupting here. */ * interrupting here. */
while (i < count) while (i < count)
free(files[i++]); xfree(files[i++]);
break; break;
} }
@ -5568,7 +5568,7 @@ void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum
alist_add(al, files[i], use_curbuf ? 2 : 1); alist_add(al, files[i], use_curbuf ? 2 : 1);
os_breakcheck(); os_breakcheck();
} }
free(files); xfree(files);
} }
if (al == &global_alist) if (al == &global_alist)
@ -5729,7 +5729,7 @@ void ex_splitview(exarg_T *eap)
theend: theend:
free(fname); xfree(fname);
} }
/* /*
@ -5908,7 +5908,7 @@ static void ex_find(exarg_T *eap)
* appears several times in the path. */ * appears several times in the path. */
count = eap->line2; count = eap->line2;
while (fname != NULL && --count > 0) { while (fname != NULL && --count > 0) {
free(fname); xfree(fname);
fname = find_file_in_path(NULL, 0, FNAME_MESS, fname = find_file_in_path(NULL, 0, FNAME_MESS,
FALSE, curbuf->b_ffname); FALSE, curbuf->b_ffname);
} }
@ -5917,7 +5917,7 @@ static void ex_find(exarg_T *eap)
if (fname != NULL) { if (fname != NULL) {
eap->arg = fname; eap->arg = fname;
do_exedit(eap, NULL); do_exedit(eap, NULL);
free(fname); xfree(fname);
} }
} }
@ -6236,10 +6236,10 @@ static char_u *prev_dir = NULL;
#if defined(EXITFREE) #if defined(EXITFREE)
void free_cd_dir(void) void free_cd_dir(void)
{ {
free(prev_dir); xfree(prev_dir);
prev_dir = NULL; prev_dir = NULL;
free(globaldir); xfree(globaldir);
globaldir = NULL; globaldir = NULL;
} }
@ -6251,7 +6251,7 @@ void free_cd_dir(void)
*/ */
void post_chdir(int local) void post_chdir(int local)
{ {
free(curwin->w_localdir); xfree(curwin->w_localdir);
curwin->w_localdir = NULL; curwin->w_localdir = NULL;
if (local) { if (local) {
/* If still in global directory, need to remember current /* If still in global directory, need to remember current
@ -6264,7 +6264,7 @@ void post_chdir(int local)
} else { } else {
/* We are now in the global directory, no need to remember its /* We are now in the global directory, no need to remember its
* name. */ * name. */
free(globaldir); xfree(globaldir);
globaldir = NULL; globaldir = NULL;
} }
@ -6330,7 +6330,7 @@ void ex_cd(exarg_T *eap)
if (KeyTyped || p_verbose >= 5) if (KeyTyped || p_verbose >= 5)
ex_pwd(eap); ex_pwd(eap);
} }
free(tofree); xfree(tofree);
} }
} }
@ -6733,7 +6733,7 @@ static void ex_redir(exarg_T *eap)
return; return;
redir_fd = open_exfile(fname, eap->forceit, mode); redir_fd = open_exfile(fname, eap->forceit, mode);
free(fname); xfree(fname);
} else if (*arg == '@') { } else if (*arg == '@') {
/* redirect to a register a-z (resp. A-Z for appending) */ /* redirect to a register a-z (resp. A-Z for appending) */
close_redir(); close_redir();
@ -6970,7 +6970,7 @@ static void ex_mkrc(exarg_T *eap)
shorten_fnames(TRUE); shorten_fnames(TRUE);
} }
} }
free(dirnow); xfree(dirnow);
} else { } else {
failed |= (put_view(fd, curwin, !using_vdir, flagp, failed |= (put_view(fd, curwin, !using_vdir, flagp,
-1) == FAIL); -1) == FAIL);
@ -6999,14 +6999,14 @@ static void ex_mkrc(exarg_T *eap)
tbuf = xmalloc(MAXPATHL); tbuf = xmalloc(MAXPATHL);
if (vim_FullName(fname, tbuf, MAXPATHL, FALSE) == OK) if (vim_FullName(fname, tbuf, MAXPATHL, FALSE) == OK)
set_vim_var_string(VV_THIS_SESSION, tbuf, -1); set_vim_var_string(VV_THIS_SESSION, tbuf, -1);
free(tbuf); xfree(tbuf);
} }
#ifdef MKSESSION_NL #ifdef MKSESSION_NL
mksession_nl = FALSE; mksession_nl = FALSE;
#endif #endif
} }
free(viewFile); xfree(viewFile);
} }
int vim_mkdir_emsg(char_u *name, int prot) int vim_mkdir_emsg(char_u *name, int prot)
@ -7189,7 +7189,7 @@ static void ex_normal(exarg_T *eap)
State = save_State; State = save_State;
setmouse(); setmouse();
ui_cursor_shape(); /* may show different cursor shape */ ui_cursor_shape(); /* may show different cursor shape */
free(arg); xfree(arg);
} }
/* /*
@ -7609,7 +7609,7 @@ eval_vars (
* postponed to avoid a delay when <afile> is not used. */ * postponed to avoid a delay when <afile> is not used. */
autocmd_fname_full = TRUE; autocmd_fname_full = TRUE;
result = FullName_save(autocmd_fname, FALSE); result = FullName_save(autocmd_fname, FALSE);
free(autocmd_fname); xfree(autocmd_fname);
autocmd_fname = result; autocmd_fname = result;
} }
if (result == NULL) { if (result == NULL) {
@ -7686,7 +7686,7 @@ eval_vars (
result = NULL; result = NULL;
} else } else
result = vim_strnsave(result, resultlen); result = vim_strnsave(result, resultlen);
free(resultbuf); xfree(resultbuf);
return result; return result;
} }
@ -7772,7 +7772,7 @@ char_u *expand_sfile(char_u *arg)
if (errormsg != NULL) { if (errormsg != NULL) {
if (*errormsg) if (*errormsg)
emsg(errormsg); emsg(errormsg);
free(result); xfree(result);
return NULL; return NULL;
} }
if (repl == NULL) { /* no match (cannot happen) */ if (repl == NULL) { /* no match (cannot happen) */
@ -7785,8 +7785,8 @@ char_u *expand_sfile(char_u *arg)
STRCPY(newres + (p - result), repl); STRCPY(newres + (p - result), repl);
len = (int)STRLEN(newres); len = (int)STRLEN(newres);
STRCAT(newres, p + srclen); STRCAT(newres, p + srclen);
free(repl); xfree(repl);
free(result); xfree(result);
result = newres; result = newres;
p = newres + len; /* continue after the match */ p = newres + len; /* continue after the match */
} }
@ -7850,10 +7850,10 @@ makeopens (
if (fputs("cd ", fd) < 0 if (fputs("cd ", fd) < 0
|| ses_put_fname(fd, sname, &ssop_flags) == FAIL || ses_put_fname(fd, sname, &ssop_flags) == FAIL
|| put_eol(fd) == FAIL) { || put_eol(fd) == FAIL) {
free(sname); xfree(sname);
return FAIL; return FAIL;
} }
free(sname); xfree(sname);
} }
/* /*
@ -8434,10 +8434,10 @@ ses_arglist (
} }
if (fputs("argadd ", fd) < 0 || ses_put_fname(fd, s, flagp) == FAIL if (fputs("argadd ", fd) < 0 || ses_put_fname(fd, s, flagp) == FAIL
|| put_eol(fd) == FAIL) { || put_eol(fd) == FAIL) {
free(buf); xfree(buf);
return FAIL; return FAIL;
} }
free(buf); xfree(buf);
} }
} }
return OK; return OK;
@ -8491,11 +8491,11 @@ static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp)
/* escape special characters */ /* escape special characters */
p = vim_strsave_fnameescape(sname, FALSE); p = vim_strsave_fnameescape(sname, FALSE);
free(sname); xfree(sname);
/* write the result */ /* write the result */
bool retval = fputs((char *)p, fd) < 0 ? FAIL : OK; bool retval = fputs((char *)p, fd) < 0 ? FAIL : OK;
free(p); xfree(p);
return retval; return retval;
} }
@ -8511,7 +8511,7 @@ static void ex_loadview(exarg_T *eap)
if (do_source(fname, FALSE, DOSO_NONE) == FAIL) { if (do_source(fname, FALSE, DOSO_NONE) == FAIL) {
EMSG2(_(e_notopen), fname); EMSG2(_(e_notopen), fname);
} }
free(fname); xfree(fname);
} }
} }
@ -8564,7 +8564,7 @@ static char_u *get_view_file(int c)
*s++ = c; *s++ = c;
STRCPY(s, ".vim"); STRCPY(s, ".vim");
free(sname); xfree(sname);
return retval; return retval;
} }
@ -8829,7 +8829,7 @@ static void ex_match(exarg_T *eap)
c = *end; c = *end;
*end = NUL; *end = NUL;
match_add(curwin, g, p + 1, 10, id, NULL); match_add(curwin, g, p + 1, 10, id, NULL);
free(g); xfree(g);
*end = c; *end = c;
} }
} }

View File

@ -281,8 +281,8 @@ static void free_msglist(struct msglist *l)
messages = l; messages = l;
while (messages != NULL) { while (messages != NULL) {
next = messages->next; next = messages->next;
free(messages->msg); xfree(messages->msg);
free(messages); xfree(messages);
messages = next; messages = next;
} }
} }
@ -505,7 +505,7 @@ static int throw_exception(void *value, int type, char_u *cmdname)
return OK; return OK;
nomem: nomem:
free(excp); xfree(excp);
suppress_errthrow = TRUE; suppress_errthrow = TRUE;
EMSG(_(e_outofmem)); EMSG(_(e_outofmem));
fail: fail:
@ -550,14 +550,14 @@ static void discard_exception(except_T *excp, int was_finished)
else else
verbose_leave(); verbose_leave();
STRCPY(IObuff, saved_IObuff); STRCPY(IObuff, saved_IObuff);
free(saved_IObuff); xfree(saved_IObuff);
} }
if (excp->type != ET_INTERRUPT) if (excp->type != ET_INTERRUPT)
free(excp->value); xfree(excp->value);
if (excp->type == ET_ERROR) if (excp->type == ET_ERROR)
free_msglist(excp->messages); free_msglist(excp->messages);
free(excp->throw_name); xfree(excp->throw_name);
free(excp); xfree(excp);
} }
/* /*
@ -727,9 +727,9 @@ static void report_pending(int action, int pending, void *value)
msg_silent = save_msg_silent; msg_silent = save_msg_silent;
if (pending == CSTP_RETURN) if (pending == CSTP_RETURN)
free(s); xfree(s);
else if (pending & CSTP_THROW) else if (pending & CSTP_THROW)
free(mesg); xfree(mesg);
} }
/* /*
@ -1165,7 +1165,7 @@ void ex_throw(exarg_T *eap)
* not throw. */ * not throw. */
if (!eap->skip && value != NULL) { if (!eap->skip && value != NULL) {
if (throw_exception(value, ET_USER, NULL) == FAIL) if (throw_exception(value, ET_USER, NULL) == FAIL)
free(value); xfree(value);
else else
do_throw(eap->cstack); do_throw(eap->cstack);
} }
@ -1977,7 +1977,7 @@ int cleanup_conditionals(struct condstack *cstack, int searched_cond, int inclus
elem = cstack->cs_emsg_silent_list; elem = cstack->cs_emsg_silent_list;
cstack->cs_emsg_silent_list = elem->next; cstack->cs_emsg_silent_list = elem->next;
emsg_silent = elem->saved_emsg_silent; emsg_silent = elem->saved_emsg_silent;
free(elem); xfree(elem);
cstack->cs_flags[idx] &= ~CSF_SILENT; cstack->cs_flags[idx] &= ~CSF_SILENT;
} }
if (stop) if (stop)

View File

@ -354,7 +354,7 @@ getcmdline (
&& c != K_KPAGEDOWN && c != K_KPAGEUP && c != K_KPAGEDOWN && c != K_KPAGEUP
&& c != K_LEFT && c != K_RIGHT && c != K_LEFT && c != K_RIGHT
&& (xpc.xp_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N))) { && (xpc.xp_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N))) {
free(lookfor); xfree(lookfor);
lookfor = NULL; lookfor = NULL;
} }
@ -593,7 +593,7 @@ getcmdline (
realloc_cmdbuff(len + 1); realloc_cmdbuff(len + 1);
ccline.cmdlen = len; ccline.cmdlen = len;
STRCPY(ccline.cmdbuff, p); STRCPY(ccline.cmdbuff, p);
free(p); xfree(p);
/* Restore the cursor or use the position set with /* Restore the cursor or use the position set with
* set_cmdline_pos(). */ * set_cmdline_pos(). */
@ -825,7 +825,7 @@ getcmdline (
) )
goto cmdline_not_changed; goto cmdline_not_changed;
free(ccline.cmdbuff); /* no commandline to return */ xfree(ccline.cmdbuff); /* no commandline to return */
ccline.cmdbuff = NULL; ccline.cmdbuff = NULL;
if (!cmd_silent) { if (!cmd_silent) {
if (cmdmsg_rl) if (cmdmsg_rl)
@ -1193,7 +1193,7 @@ getcmdline (
int len; int len;
int old_firstc; int old_firstc;
free(ccline.cmdbuff); xfree(ccline.cmdbuff);
xpc.xp_context = EXPAND_NOTHING; xpc.xp_context = EXPAND_NOTHING;
if (hiscnt == hislen) if (hiscnt == hislen)
p = lookfor; /* back to the old one */ p = lookfor; /* back to the old one */
@ -1476,13 +1476,13 @@ returncmd:
add_to_history(histype, ccline.cmdbuff, TRUE, add_to_history(histype, ccline.cmdbuff, TRUE,
histype == HIST_SEARCH ? firstc : NUL); histype == HIST_SEARCH ? firstc : NUL);
if (firstc == ':') { if (firstc == ':') {
free(new_last_cmdline); xfree(new_last_cmdline);
new_last_cmdline = vim_strsave(ccline.cmdbuff); new_last_cmdline = vim_strsave(ccline.cmdbuff);
} }
} }
if (gotesc) { /* abandon command line */ if (gotesc) { /* abandon command line */
free(ccline.cmdbuff); xfree(ccline.cmdbuff);
ccline.cmdbuff = NULL; ccline.cmdbuff = NULL;
if (msg_scrolled == 0) if (msg_scrolled == 0)
compute_cmdrow(); compute_cmdrow();
@ -1958,7 +1958,7 @@ static void realloc_cmdbuff(int len)
* there, thus copy up to the NUL and add a NUL. */ * there, thus copy up to the NUL and add a NUL. */
memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen); memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen);
ccline.cmdbuff[ccline.cmdlen] = NUL; ccline.cmdbuff[ccline.cmdlen] = NUL;
free(p); xfree(p);
if (ccline.xpc != NULL if (ccline.xpc != NULL
&& ccline.xpc->xp_pattern != NULL && ccline.xpc->xp_pattern != NULL
@ -1978,7 +1978,7 @@ static char_u *arshape_buf = NULL;
# if defined(EXITFREE) # if defined(EXITFREE)
void free_cmdline_buf(void) void free_cmdline_buf(void)
{ {
free(arshape_buf); xfree(arshape_buf);
} }
# endif # endif
@ -2017,7 +2017,7 @@ static void draw_cmdline(int start, int len)
if (len * 2 + 2 > buflen) { if (len * 2 + 2 > buflen) {
/* Re-allocate the buffer. We keep it around to avoid a lot of /* Re-allocate the buffer. We keep it around to avoid a lot of
* alloc()/free() calls. */ * alloc()/free() calls. */
free(arshape_buf); xfree(arshape_buf);
buflen = len * 2 + 2; buflen = len * 2 + 2;
arshape_buf = xmalloc(buflen); arshape_buf = xmalloc(buflen);
} }
@ -2291,7 +2291,7 @@ char_u *save_cmdline_alloc(void)
void restore_cmdline_alloc(char_u *p) void restore_cmdline_alloc(char_u *p)
{ {
restore_cmdline((struct cmdline_info *)p); restore_cmdline((struct cmdline_info *)p);
free(p); xfree(p);
} }
/* /*
@ -2368,7 +2368,7 @@ cmdline_paste (
cmdline_paste_str(p, literally); cmdline_paste_str(p, literally);
if (allocated) if (allocated)
free(arg); xfree(arg);
return OK; return OK;
} }
@ -2616,7 +2616,7 @@ nextwild (
p2 = ExpandOne(xp, p1, p2 = ExpandOne(xp, p1,
vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len),
use_options, type); use_options, type);
free(p1); xfree(p1);
/* longest match: make sure it is not shorter, happens with :help */ /* longest match: make sure it is not shorter, happens with :help */
if (p2 != NULL && type == WILD_LONGEST) { if (p2 != NULL && type == WILD_LONGEST) {
for (j = 0; j < xp->xp_pattern_len; ++j) for (j = 0; j < xp->xp_pattern_len; ++j)
@ -2624,7 +2624,7 @@ nextwild (
|| ccline.cmdbuff[i + j] == '?') || ccline.cmdbuff[i + j] == '?')
break; break;
if ((int)STRLEN(p2) < j) { if ((int)STRLEN(p2) < j) {
free(p2); xfree(p2);
p2 = NULL; p2 = NULL;
} }
} }
@ -2644,7 +2644,7 @@ nextwild (
ccline.cmdlen += difflen; ccline.cmdlen += difflen;
ccline.cmdpos += difflen; ccline.cmdpos += difflen;
} }
free(p2); xfree(p2);
redrawcmd(); redrawcmd();
cursorcmd(); cursorcmd();
@ -2755,7 +2755,7 @@ ExpandOne (
if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) { if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) {
FreeWild(xp->xp_numfiles, xp->xp_files); FreeWild(xp->xp_numfiles, xp->xp_files);
xp->xp_numfiles = -1; xp->xp_numfiles = -1;
free(orig_save); xfree(orig_save);
orig_save = NULL; orig_save = NULL;
} }
findex = 0; findex = 0;
@ -2764,7 +2764,7 @@ ExpandOne (
return NULL; return NULL;
if (xp->xp_numfiles == -1) { if (xp->xp_numfiles == -1) {
free(orig_save); xfree(orig_save);
orig_save = orig; orig_save = orig;
orig_saved = TRUE; orig_saved = TRUE;
@ -2872,7 +2872,7 @@ ExpandOne (
/* Free "orig" if it wasn't stored in "orig_save". */ /* Free "orig" if it wasn't stored in "orig_save". */
if (!orig_saved) if (!orig_saved)
free(orig); xfree(orig);
return ss; return ss;
} }
@ -2930,11 +2930,11 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
/* for ":set path=" we need to escape spaces twice */ /* for ":set path=" we need to escape spaces twice */
if (xp->xp_backslash == XP_BS_THREE) { if (xp->xp_backslash == XP_BS_THREE) {
p = vim_strsave_escaped(files[i], (char_u *)" "); p = vim_strsave_escaped(files[i], (char_u *)" ");
free(files[i]); xfree(files[i]);
files[i] = p; files[i] = p;
#if defined(BACKSLASH_IN_FILENAME) #if defined(BACKSLASH_IN_FILENAME)
p = vim_strsave_escaped(files[i], (char_u *)" "); p = vim_strsave_escaped(files[i], (char_u *)" ");
free(files[i]); xfree(files[i]);
files[i] = p; files[i] = p;
#endif #endif
} }
@ -2943,7 +2943,7 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
#else #else
p = vim_strsave_fnameescape(files[i], xp->xp_shell); p = vim_strsave_fnameescape(files[i], xp->xp_shell);
#endif #endif
free(files[i]); xfree(files[i]);
files[i] = p; files[i] = p;
/* If 'str' starts with "\~", replace "~" at start of /* If 'str' starts with "\~", replace "~" at start of
@ -2964,7 +2964,7 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
*/ */
for (i = 0; i < numfiles; ++i) { for (i = 0; i < numfiles; ++i) {
p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); p = vim_strsave_escaped(files[i], (char_u *)"\\|\"");
free(files[i]); xfree(files[i]);
files[i] = p; files[i] = p;
} }
} }
@ -2998,7 +2998,7 @@ char_u *vim_strsave_fnameescape(char_u *fname, int shell) FUNC_ATTR_NONNULL_RET
/* For csh and similar shells need to put two backslashes before '!'. /* For csh and similar shells need to put two backslashes before '!'.
* One is taken by Vim, one by the shell. */ * One is taken by Vim, one by the shell. */
char_u *s = vim_strsave_escaped(p, (char_u *)"!"); char_u *s = vim_strsave_escaped(p, (char_u *)"!");
free(p); xfree(p);
p = s; p = s;
} }
#endif #endif
@ -3020,7 +3020,7 @@ static void escape_fname(char_u **pp)
char_u *p = xmalloc(STRLEN(*pp) + 2); char_u *p = xmalloc(STRLEN(*pp) + 2);
p[0] = '\\'; p[0] = '\\';
STRCPY(p + 1, *pp); STRCPY(p + 1, *pp);
free(*pp); xfree(*pp);
*pp = p; *pp = p;
} }
@ -3036,7 +3036,7 @@ void tilde_replace(char_u *orig_pat, int num_files, char_u **files)
if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) { if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) {
for (i = 0; i < num_files; ++i) { for (i = 0; i < num_files; ++i) {
p = home_replace_save(NULL, files[i]); p = home_replace_save(NULL, files[i]);
free(files[i]); xfree(files[i]);
files[i] = p; files[i] = p;
} }
} }
@ -3154,8 +3154,8 @@ static int showmatches(expand_T *xp, int wildmenu)
halved_slash = backslash_halve_save( halved_slash = backslash_halve_save(
exp_path != NULL ? exp_path : files_found[k]); exp_path != NULL ? exp_path : files_found[k]);
j = os_isdir(halved_slash); j = os_isdir(halved_slash);
free(exp_path); xfree(exp_path);
free(halved_slash); xfree(halved_slash);
} else } else
/* Expansion was done here, file names are literal. */ /* Expansion was done here, file names are literal. */
j = os_isdir(files_found[k]); j = os_isdir(files_found[k]);
@ -3515,7 +3515,7 @@ expand_cmdline (
*matchcount = 0; *matchcount = 0;
*matches = NULL; *matches = NULL;
} }
free(file_str); xfree(file_str);
return EXPAND_OK; return EXPAND_OK;
} }
@ -3610,7 +3610,7 @@ ExpandFromContext (
/* Expand wildcards, supporting %:h and the like. */ /* Expand wildcards, supporting %:h and the like. */
ret = expand_wildcards_eval(&pat, num_file, file, flags); ret = expand_wildcards_eval(&pat, num_file, file, flags);
if (free_pat) if (free_pat)
free(pat); xfree(pat);
return ret; return ret;
} }
@ -3887,9 +3887,9 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
STRMOVE(s, s + l); STRMOVE(s, s + l);
((char_u **)ga.ga_data)[ga.ga_len++] = s; ((char_u **)ga.ga_data)[ga.ga_len++] = s;
} else } else
free(s); xfree(s);
} }
free(*file); xfree(*file);
} }
} }
if (*e != NUL) if (*e != NUL)
@ -3898,10 +3898,10 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
*file = ga.ga_data; *file = ga.ga_data;
*num_file = ga.ga_len; *num_file = ga.ga_len;
free(buf); xfree(buf);
free(pat); xfree(pat);
if (mustfree) if (mustfree)
free(path); xfree(path);
} }
/* /*
@ -3946,7 +3946,7 @@ static void * call_user_expand_func(user_expand_func_T user_expand_func,
if (ccline.cmdbuff != NULL) if (ccline.cmdbuff != NULL)
ccline.cmdbuff[ccline.cmdlen] = keep; ccline.cmdbuff[ccline.cmdlen] = keep;
free(args[0]); xfree(args[0]);
return ret; return ret;
} }
@ -3986,7 +3986,7 @@ static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file,
if (*e != NUL) if (*e != NUL)
++e; ++e;
} }
free(retstr); xfree(retstr);
*file = ga.ga_data; *file = ga.ga_data;
*num_file = ga.ga_len; *num_file = ga.ga_len;
return OK; return OK;
@ -4039,7 +4039,7 @@ static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname
char_u *s = xmalloc(size); char_u *s = xmalloc(size);
snprintf((char *)s, size, "%s/%s*.vim", dirnames[i], pat); snprintf((char *)s, size, "%s/%s*.vim", dirnames[i], pat);
globpath(p_rtp, s, &ga, 0); globpath(p_rtp, s, &ga, 0);
free(s); xfree(s);
} }
for (int i = 0; i < ga.ga_len; i++) { for (int i = 0; i < ga.ga_len; i++) {
@ -4108,7 +4108,7 @@ void globpath(char_u *path, char_u *file, garray_T *ga, int expand_options)
} }
} }
free(buf); xfree(buf);
} }
@ -4210,7 +4210,7 @@ void init_history(void)
if (i >= 0) /* copy newest entries */ if (i >= 0) /* copy newest entries */
temp[i] = history[type][j]; temp[i] = history[type][j];
else { /* remove older entries */ else { /* remove older entries */
free(history[type][j].hisstr); xfree(history[type][j].hisstr);
history[type][j].hisstr = NULL; history[type][j].hisstr = NULL;
} }
if (--j < 0) if (--j < 0)
@ -4220,7 +4220,7 @@ void init_history(void)
} }
hisidx[type] = newlen - 1; hisidx[type] = newlen - 1;
} }
free(history[type]); xfree(history[type]);
history[type] = temp; history[type] = temp;
} }
} }
@ -4347,7 +4347,7 @@ add_to_history (
if (maptick == last_maptick) { if (maptick == last_maptick) {
/* Current line is from the same mapping, remove it */ /* Current line is from the same mapping, remove it */
hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]];
free(hisptr->hisstr); xfree(hisptr->hisstr);
clear_hist_entry(hisptr); clear_hist_entry(hisptr);
--hisnum[histype]; --hisnum[histype];
if (--hisidx[HIST_SEARCH] < 0) if (--hisidx[HIST_SEARCH] < 0)
@ -4359,7 +4359,7 @@ add_to_history (
if (++hisidx[histype] == hislen) if (++hisidx[histype] == hislen)
hisidx[histype] = 0; hisidx[histype] = 0;
hisptr = &history[histype][hisidx[histype]]; hisptr = &history[histype][hisidx[histype]];
free(hisptr->hisstr); xfree(hisptr->hisstr);
/* Store the separator after the NUL of the string. */ /* Store the separator after the NUL of the string. */
len = (int)STRLEN(new_entry); len = (int)STRLEN(new_entry);
@ -4532,7 +4532,7 @@ int clr_history(int histype)
if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) { if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) {
hisptr = history[histype]; hisptr = history[histype];
for (i = hislen; i--; ) { for (i = hislen; i--; ) {
free(hisptr->hisstr); xfree(hisptr->hisstr);
clear_hist_entry(hisptr); clear_hist_entry(hisptr);
} }
hisidx[histype] = -1; /* mark history as cleared */ hisidx[histype] = -1; /* mark history as cleared */
@ -4571,7 +4571,7 @@ int del_history_entry(int histype, char_u *str)
break; break;
if (vim_regexec(&regmatch, hisptr->hisstr, (colnr_T)0)) { if (vim_regexec(&regmatch, hisptr->hisstr, (colnr_T)0)) {
found = TRUE; found = TRUE;
free(hisptr->hisstr); xfree(hisptr->hisstr);
clear_hist_entry(hisptr); clear_hist_entry(hisptr);
} else { } else {
if (i != last) { if (i != last) {
@ -4603,7 +4603,7 @@ int del_history_idx(int histype, int idx)
if (i < 0) if (i < 0)
return FALSE; return FALSE;
idx = hisidx[histype]; idx = hisidx[histype];
free(history[histype][i].hisstr); xfree(history[histype][i].hisstr);
/* When deleting the last added search string in a mapping, reset /* When deleting the last added search string in a mapping, reset
* last_maptick, so that the last added search string isn't deleted again. * last_maptick, so that the last added search string isn't deleted again.
@ -4837,7 +4837,7 @@ int read_viminfo_history(vir_T *virp, int writing)
viminfo_history[type][viminfo_hisidx[type]++] = p; viminfo_history[type][viminfo_hisidx[type]++] = p;
} }
} }
free(val); xfree(val);
} }
return viminfo_readline(virp); return viminfo_readline(virp);
} }
@ -4875,7 +4875,7 @@ void finish_viminfo_history(void)
idx = hislen - 1; idx = hislen - 1;
} }
for (i = 0; i < viminfo_hisidx[type]; i++) { for (i = 0; i < viminfo_hisidx[type]; i++) {
free(history[type][idx].hisstr); xfree(history[type][idx].hisstr);
history[type][idx].hisstr = viminfo_history[type][i]; history[type][idx].hisstr = viminfo_history[type][i];
history[type][idx].viminfo = TRUE; history[type][idx].viminfo = TRUE;
if (--idx < 0) if (--idx < 0)
@ -4887,7 +4887,7 @@ void finish_viminfo_history(void)
history[type][idx++].hisnum = ++hisnum[type]; history[type][idx++].hisnum = ++hisnum[type];
idx %= hislen; idx %= hislen;
} }
free(viminfo_history[type]); xfree(viminfo_history[type]);
viminfo_history[type] = NULL; viminfo_history[type] = NULL;
viminfo_hisidx[type] = 0; viminfo_hisidx[type] = 0;
} }
@ -4974,8 +4974,8 @@ void write_viminfo_history(FILE *fp, int merge)
} }
for (i = 0; i < viminfo_hisidx[type]; ++i) for (i = 0; i < viminfo_hisidx[type]; ++i)
if (viminfo_history[type] != NULL) if (viminfo_history[type] != NULL)
free(viminfo_history[type][i]); xfree(viminfo_history[type][i]);
free(viminfo_history[type]); xfree(viminfo_history[type]);
viminfo_history[type] = NULL; viminfo_history[type] = NULL;
viminfo_hisidx[type] = 0; viminfo_hisidx[type] = 0;
} }
@ -5161,7 +5161,7 @@ static int ex_window(void)
if (aborting() && cmdwin_result != K_IGNORE) if (aborting() && cmdwin_result != K_IGNORE)
cmdwin_result = Ctrl_C; cmdwin_result = Ctrl_C;
/* Set the new command line from the cmdline buffer. */ /* Set the new command line from the cmdline buffer. */
free(ccline.cmdbuff); xfree(ccline.cmdbuff);
if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) { /* :qa[!] typed */ if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) { /* :qa[!] typed */
char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!";
@ -5257,13 +5257,13 @@ char_u *script_get(exarg_T *eap, char_u *cmd)
NUL, eap->cookie, 0); NUL, eap->cookie, 0);
if (theline == NULL || STRCMP(end_pattern, theline) == 0) { if (theline == NULL || STRCMP(end_pattern, theline) == 0) {
free(theline); xfree(theline);
break; break;
} }
ga_concat(&ga, theline); ga_concat(&ga, theline);
ga_append(&ga, '\n'); ga_append(&ga, '\n');
free(theline); xfree(theline);
} }
ga_append(&ga, NUL); ga_append(&ga, NUL);

View File

@ -496,19 +496,19 @@ vim_findfile_init (
} }
if (temp == NULL || wc_path == NULL) { if (temp == NULL || wc_path == NULL) {
free(buf); xfree(buf);
free(temp); xfree(temp);
free(wc_path); xfree(wc_path);
goto error_return; goto error_return;
} }
STRCPY(temp, search_ctx->ffsc_fix_path + len); STRCPY(temp, search_ctx->ffsc_fix_path + len);
STRCAT(temp, search_ctx->ffsc_wc_path); STRCAT(temp, search_ctx->ffsc_wc_path);
free(search_ctx->ffsc_wc_path); xfree(search_ctx->ffsc_wc_path);
free(wc_path); xfree(wc_path);
search_ctx->ffsc_wc_path = temp; search_ctx->ffsc_wc_path = temp;
} }
free(buf); xfree(buf);
} }
sptr = ff_create_stack_element(ff_expand_buffer, sptr = ff_create_stack_element(ff_expand_buffer,
@ -563,7 +563,7 @@ void vim_findfile_cleanup(void *ctx)
vim_findfile_free_visited(ctx); vim_findfile_free_visited(ctx);
ff_clear(ctx); ff_clear(ctx);
free(ctx); xfree(ctx);
} }
/* /*
@ -947,7 +947,7 @@ char_u *vim_findfile(void *search_ctx_arg)
break; break;
} }
free(file_path); xfree(file_path);
return NULL; return NULL;
} }
@ -975,8 +975,8 @@ static void vim_findfile_free_visited_list(ff_visited_list_hdr_T **list_headp)
vp = (*list_headp)->ffvl_next; vp = (*list_headp)->ffvl_next;
ff_free_visited_list((*list_headp)->ffvl_visited_list); ff_free_visited_list((*list_headp)->ffvl_visited_list);
free((*list_headp)->ffvl_filename); xfree((*list_headp)->ffvl_filename);
free(*list_headp); xfree(*list_headp);
*list_headp = vp; *list_headp = vp;
} }
*list_headp = NULL; *list_headp = NULL;
@ -988,8 +988,8 @@ static void ff_free_visited_list(ff_visited_T *vl)
while (vl != NULL) { while (vl != NULL) {
vp = vl->ffv_next; vp = vl->ffv_next;
free(vl->ffv_wc_path); xfree(vl->ffv_wc_path);
free(vl); xfree(vl);
vl = vp; vl = vp;
} }
vl = NULL; vl = NULL;
@ -1205,13 +1205,13 @@ static ff_stack_T *ff_pop(ff_search_ctx_T *search_ctx)
static void ff_free_stack_element(ff_stack_T *stack_ptr) static void ff_free_stack_element(ff_stack_T *stack_ptr)
{ {
/* free handles possible NULL pointers */ /* free handles possible NULL pointers */
free(stack_ptr->ffs_fix_path); xfree(stack_ptr->ffs_fix_path);
free(stack_ptr->ffs_wc_path); xfree(stack_ptr->ffs_wc_path);
if (stack_ptr->ffs_filearray != NULL) if (stack_ptr->ffs_filearray != NULL)
FreeWild(stack_ptr->ffs_filearray_size, stack_ptr->ffs_filearray); FreeWild(stack_ptr->ffs_filearray_size, stack_ptr->ffs_filearray);
free(stack_ptr); xfree(stack_ptr);
} }
/* /*
@ -1225,19 +1225,19 @@ static void ff_clear(ff_search_ctx_T *search_ctx)
while ((sptr = ff_pop(search_ctx)) != NULL) while ((sptr = ff_pop(search_ctx)) != NULL)
ff_free_stack_element(sptr); ff_free_stack_element(sptr);
free(search_ctx->ffsc_file_to_search); xfree(search_ctx->ffsc_file_to_search);
free(search_ctx->ffsc_start_dir); xfree(search_ctx->ffsc_start_dir);
free(search_ctx->ffsc_fix_path); xfree(search_ctx->ffsc_fix_path);
free(search_ctx->ffsc_wc_path); xfree(search_ctx->ffsc_wc_path);
if (search_ctx->ffsc_stopdirs_v != NULL) { if (search_ctx->ffsc_stopdirs_v != NULL) {
int i = 0; int i = 0;
while (search_ctx->ffsc_stopdirs_v[i] != NULL) { while (search_ctx->ffsc_stopdirs_v[i] != NULL) {
free(search_ctx->ffsc_stopdirs_v[i]); xfree(search_ctx->ffsc_stopdirs_v[i]);
i++; i++;
} }
free(search_ctx->ffsc_stopdirs_v); xfree(search_ctx->ffsc_stopdirs_v);
} }
search_ctx->ffsc_stopdirs_v = NULL; search_ctx->ffsc_stopdirs_v = NULL;
@ -1327,9 +1327,9 @@ static void *fdip_search_ctx = NULL;
#if defined(EXITFREE) #if defined(EXITFREE)
void free_findfile(void) void free_findfile(void)
{ {
free(ff_file_to_find); xfree(ff_file_to_find);
vim_findfile_cleanup(fdip_search_ctx); vim_findfile_cleanup(fdip_search_ctx);
free(ff_expand_buffer); xfree(ff_expand_buffer);
} }
#endif #endif
@ -1382,7 +1382,7 @@ find_file_in_path_option (
expand_env(ptr, NameBuff, MAXPATHL); expand_env(ptr, NameBuff, MAXPATHL);
ptr[len] = save_char; ptr[len] = save_char;
free(ff_file_to_find); xfree(ff_file_to_find);
ff_file_to_find = vim_strsave(NameBuff); ff_file_to_find = vim_strsave(NameBuff);
} }
@ -1487,7 +1487,7 @@ find_file_in_path_option (
fdip_search_ctx, FALSE, rel_fname); fdip_search_ctx, FALSE, rel_fname);
if (fdip_search_ctx != NULL) if (fdip_search_ctx != NULL)
did_findfile_init = TRUE; did_findfile_init = TRUE;
free(buf); xfree(buf);
} }
} }
} }

View File

@ -881,12 +881,12 @@ retry:
notconverted = TRUE; notconverted = TRUE;
conv_error = 0; conv_error = 0;
if (fenc_alloced) if (fenc_alloced)
free(fenc); xfree(fenc);
fenc = (char_u *)""; fenc = (char_u *)"";
fenc_alloced = FALSE; fenc_alloced = FALSE;
} else { } else {
if (fenc_alloced) if (fenc_alloced)
free(fenc); xfree(fenc);
if (fenc_next != NULL) { if (fenc_next != NULL) {
fenc = next_fenc(&fenc_next); fenc = next_fenc(&fenc_next);
fenc_alloced = (fenc_next != NULL); fenc_alloced = (fenc_next != NULL);
@ -897,7 +897,7 @@ retry:
} }
if (tmpname != NULL) { if (tmpname != NULL) {
os_remove((char *)tmpname); // delete converted file os_remove((char *)tmpname); // delete converted file
free(tmpname); xfree(tmpname);
tmpname = NULL; tmpname = NULL;
} }
} }
@ -1026,7 +1026,7 @@ retry:
} }
if (linerest) /* copy characters from the previous buffer */ if (linerest) /* copy characters from the previous buffer */
memmove(new_buffer, ptr - linerest, (size_t)linerest); memmove(new_buffer, ptr - linerest, (size_t)linerest);
free(buffer); xfree(buffer);
buffer = new_buffer; buffer = new_buffer;
ptr = buffer + linerest; ptr = buffer + linerest;
line_start = buffer; line_start = buffer;
@ -1215,7 +1215,7 @@ retry:
} else { } else {
/* BOM detected: set "fenc" and jump back */ /* BOM detected: set "fenc" and jump back */
if (fenc_alloced) if (fenc_alloced)
free(fenc); xfree(fenc);
fenc = ccname; fenc = ccname;
fenc_alloced = FALSE; fenc_alloced = FALSE;
} }
@ -1738,7 +1738,7 @@ failed:
OPT_FREE | OPT_LOCAL, 0); OPT_FREE | OPT_LOCAL, 0);
} }
if (fenc_alloced) if (fenc_alloced)
free(fenc); xfree(fenc);
# ifdef USE_ICONV # ifdef USE_ICONV
if (iconv_fd != (iconv_t)-1) { if (iconv_fd != (iconv_t)-1) {
iconv_close(iconv_fd); iconv_close(iconv_fd);
@ -1757,7 +1757,7 @@ failed:
fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC); fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC);
} }
#endif #endif
free(buffer); xfree(buffer);
#ifdef HAVE_DUP #ifdef HAVE_DUP
if (read_stdin) { if (read_stdin) {
@ -1769,7 +1769,7 @@ failed:
if (tmpname != NULL) { if (tmpname != NULL) {
os_remove((char *)tmpname); // delete converted file os_remove((char *)tmpname); // delete converted file
free(tmpname); xfree(tmpname);
} }
--no_wait_return; /* may wait for return now */ --no_wait_return; /* may wait for return now */
@ -1886,7 +1886,7 @@ failed:
c = TRUE; c = TRUE;
msg_add_lines(c, (long)linecnt, filesize); msg_add_lines(c, (long)linecnt, filesize);
free(keep_msg); xfree(keep_msg);
keep_msg = NULL; keep_msg = NULL;
msg_scrolled_ign = TRUE; msg_scrolled_ign = TRUE;
p = msg_trunc_attr(IObuff, FALSE, 0); p = msg_trunc_attr(IObuff, FALSE, 0);
@ -2084,7 +2084,7 @@ void set_forced_fenc(exarg_T *eap)
if (eap->force_enc != 0) { if (eap->force_enc != 0) {
char_u *fenc = enc_canonize(eap->cmd + eap->force_enc); char_u *fenc = enc_canonize(eap->cmd + eap->force_enc);
set_string_option_direct((char_u *)"fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0); set_string_option_direct((char_u *)"fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0);
free(fenc); xfree(fenc);
} }
} }
@ -2113,7 +2113,7 @@ static char_u *next_fenc(char_u **pp)
r = vim_strnsave(*pp, (int)(p - *pp)); r = vim_strnsave(*pp, (int)(p - *pp));
*pp = p + 1; *pp = p + 1;
p = enc_canonize(r); p = enc_canonize(r);
free(r); xfree(r);
r = p; r = p;
} }
return r; return r;
@ -2157,7 +2157,7 @@ readfile_charconvert (
MSG(errmsg); MSG(errmsg);
if (tmpname != NULL) { if (tmpname != NULL) {
os_remove((char *)tmpname); // delete converted file os_remove((char *)tmpname); // delete converted file
free(tmpname); xfree(tmpname);
tmpname = NULL; tmpname = NULL;
} }
} }
@ -2816,7 +2816,7 @@ buf_write (
*/ */
backup = modname(rootname, backup_ext, FALSE); backup = modname(rootname, backup_ext, FALSE);
if (backup == NULL) { if (backup == NULL) {
free(rootname); xfree(rootname);
some_error = TRUE; /* out of memory */ some_error = TRUE; /* out of memory */
goto nobackup; goto nobackup;
} }
@ -2832,7 +2832,7 @@ buf_write (
* link). If we don't check here, we either ruin the file when * link). If we don't check here, we either ruin the file when
* copying or erase it after writing. * copying or erase it after writing.
*/ */
free(backup); xfree(backup);
backup = NULL; /* no backup file to delete */ backup = NULL; /* no backup file to delete */
} else if (!p_bk) { } else if (!p_bk) {
/* /*
@ -2851,13 +2851,13 @@ buf_write (
} }
/* They all exist??? Must be something wrong. */ /* They all exist??? Must be something wrong. */
if (*wp == 'a') { if (*wp == 'a') {
free(backup); xfree(backup);
backup = NULL; backup = NULL;
} }
} }
} }
} }
free(rootname); xfree(rootname);
/* /*
* Try to create the backup file * Try to create the backup file
@ -2871,7 +2871,7 @@ buf_write (
O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW, O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW,
perm & 0777); perm & 0777);
if (bfd < 0) { if (bfd < 0) {
free(backup); xfree(backup);
backup = NULL; backup = NULL;
} else { } else {
/* set file protection same as original file, but /* set file protection same as original file, but
@ -2939,7 +2939,7 @@ buf_write (
} }
nobackup: nobackup:
close(fd); /* ignore errors for closing read file */ close(fd); /* ignore errors for closing read file */
free(copybuf); xfree(copybuf);
if (backup == NULL && errmsg == NULL) if (backup == NULL && errmsg == NULL)
errmsg = (char_u *)_( errmsg = (char_u *)_(
@ -2986,7 +2986,7 @@ nobackup:
backup = NULL; backup = NULL;
else { else {
backup = modname(rootname, backup_ext, FALSE); backup = modname(rootname, backup_ext, FALSE);
free(rootname); xfree(rootname);
} }
if (backup != NULL) { if (backup != NULL) {
@ -3004,7 +3004,7 @@ nobackup:
--*p; --*p;
/* They all exist??? Must be something wrong! */ /* They all exist??? Must be something wrong! */
if (*p == 'a') { if (*p == 'a') {
free(backup); xfree(backup);
backup = NULL; backup = NULL;
} }
} }
@ -3023,7 +3023,7 @@ nobackup:
if (vim_rename(fname, backup) == 0) if (vim_rename(fname, backup) == 0)
break; break;
free(backup); /* don't do the rename below */ xfree(backup); /* don't do the rename below */
backup = NULL; backup = NULL;
} }
} }
@ -3250,7 +3250,7 @@ restore_backup:
} }
if (wfname != fname) if (wfname != fname)
free(wfname); xfree(wfname);
goto fail; goto fail;
} }
errmsg = NULL; errmsg = NULL;
@ -3446,7 +3446,7 @@ restore_backup:
} }
} }
os_remove((char *)wfname); os_remove((char *)wfname);
free(wfname); xfree(wfname);
} }
if (end == 0) { if (end == 0) {
@ -3606,7 +3606,7 @@ restore_backup:
EMSG(_("E205: Patchmode: can't save original file")); EMSG(_("E205: Patchmode: can't save original file"));
else if (!os_file_exists((char_u *)org)) { else if (!os_file_exists((char_u *)org)) {
vim_rename(backup, (char_u *)org); vim_rename(backup, (char_u *)org);
free(backup); /* don't delete the file */ xfree(backup); /* don't delete the file */
backup = NULL; backup = NULL;
#ifdef UNIX #ifdef UNIX
set_file_time((char_u *)org, set_file_time((char_u *)org,
@ -3632,7 +3632,7 @@ restore_backup:
} }
if (org != NULL) { if (org != NULL) {
os_setperm((char_u *)org, os_getperm(fname) & 0777); os_setperm((char_u *)org, os_getperm(fname) & 0777);
free(org); xfree(org);
} }
} }
@ -3655,11 +3655,11 @@ nofail:
/* Done saving, we accept changed buffer warnings again */ /* Done saving, we accept changed buffer warnings again */
buf->b_saving = false; buf->b_saving = false;
free(backup); xfree(backup);
if (buffer != smallbuf) if (buffer != smallbuf)
free(buffer); xfree(buffer);
free(fenc_tofree); xfree(fenc_tofree);
free(write_info.bw_conv_buf); xfree(write_info.bw_conv_buf);
# ifdef USE_ICONV # ifdef USE_ICONV
if (write_info.bw_iconv_fd != (iconv_t)-1) { if (write_info.bw_iconv_fd != (iconv_t)-1) {
iconv_close(write_info.bw_iconv_fd); iconv_close(write_info.bw_iconv_fd);
@ -3692,7 +3692,7 @@ nofail:
STRCAT(IObuff, errmsg); STRCAT(IObuff, errmsg);
emsg(IObuff); emsg(IObuff);
if (errmsg_allocated) if (errmsg_allocated)
free(errmsg); xfree(errmsg);
retval = FAIL; retval = FAIL;
if (end == 0) { if (end == 0) {
@ -4314,7 +4314,7 @@ void shorten_fnames(int force)
&& (force && (force
|| buf->b_sfname == NULL || buf->b_sfname == NULL
|| path_is_absolute_path(buf->b_sfname))) { || path_is_absolute_path(buf->b_sfname))) {
free(buf->b_sfname); xfree(buf->b_sfname);
buf->b_sfname = NULL; buf->b_sfname = NULL;
p = path_shorten_fname(buf->b_ffname, dirname); p = path_shorten_fname(buf->b_ffname, dirname);
if (p != NULL) { if (p != NULL) {
@ -4366,7 +4366,7 @@ modname (
retval = xmalloc(MAXPATHL + extlen + 3); retval = xmalloc(MAXPATHL + extlen + 3);
if (os_dirname(retval, MAXPATHL) == FAIL || if (os_dirname(retval, MAXPATHL) == FAIL ||
(fnamelen = (int)STRLEN(retval)) == 0) { (fnamelen = (int)STRLEN(retval)) == 0) {
free(retval); xfree(retval);
return NULL; return NULL;
} }
if (!after_pathsep(retval, retval + fnamelen)) { if (!after_pathsep(retval, retval + fnamelen)) {
@ -4596,7 +4596,7 @@ int vim_rename(char_u *from, char_u *to)
break; break;
} }
free(buffer); xfree(buffer);
close(fd_in); close(fd_in);
if (close(fd_out) < 0) if (close(fd_out) < 0)
errmsg = _("E209: Error closing \"%s\""); errmsg = _("E209: Error closing \"%s\"");
@ -4705,11 +4705,11 @@ static int move_lines(buf_T *frombuf, buf_T *tobuf)
for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; ++lnum) { for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; ++lnum) {
p = vim_strsave(ml_get_buf(frombuf, lnum, FALSE)); p = vim_strsave(ml_get_buf(frombuf, lnum, FALSE));
if (ml_append(lnum - 1, p, 0, FALSE) == FAIL) { if (ml_append(lnum - 1, p, 0, FALSE) == FAIL) {
free(p); xfree(p);
retval = FAIL; retval = FAIL;
break; break;
} }
free(p); xfree(p);
} }
/* Delete all the lines in "frombuf". */ /* Delete all the lines in "frombuf". */
@ -4922,8 +4922,8 @@ buf_check_timestamp (
already_warned = TRUE; already_warned = TRUE;
} }
free(path); xfree(path);
free(tbuf); xfree(tbuf);
} }
if (reload) { if (reload) {
@ -5041,7 +5041,7 @@ void buf_reload(buf_T *buf, int orig_mode)
} }
} }
} }
free(ea.cmd); xfree(ea.cmd);
if (savebuf != NULL && buf_valid(savebuf)) if (savebuf != NULL && buf_valid(savebuf))
wipe_buffer(savebuf, FALSE); wipe_buffer(savebuf, FALSE);
@ -5315,7 +5315,7 @@ static void show_autocmd(AutoPat *ap, event_T event)
*/ */
static void au_remove_pat(AutoPat *ap) static void au_remove_pat(AutoPat *ap)
{ {
free(ap->pat); xfree(ap->pat);
ap->pat = NULL; ap->pat = NULL;
ap->buflocal_nr = -1; ap->buflocal_nr = -1;
au_need_clean = TRUE; au_need_clean = TRUE;
@ -5329,7 +5329,7 @@ static void au_remove_cmds(AutoPat *ap)
AutoCmd *ac; AutoCmd *ac;
for (ac = ap->cmds; ac != NULL; ac = ac->next) { for (ac = ap->cmds; ac != NULL; ac = ac->next) {
free(ac->cmd); xfree(ac->cmd);
ac->cmd = NULL; ac->cmd = NULL;
} }
au_need_clean = TRUE; au_need_clean = TRUE;
@ -5361,8 +5361,8 @@ static void au_cleanup(void)
* the command has been marked for deletion */ * the command has been marked for deletion */
if (ap->pat == NULL || ac->cmd == NULL) { if (ap->pat == NULL || ac->cmd == NULL) {
*prev_ac = ac->next; *prev_ac = ac->next;
free(ac->cmd); xfree(ac->cmd);
free(ac); xfree(ac);
} else } else
prev_ac = &(ac->next); prev_ac = &(ac->next);
} }
@ -5371,7 +5371,7 @@ static void au_cleanup(void)
if (ap->pat == NULL) { if (ap->pat == NULL) {
*prev_ap = ap->next; *prev_ap = ap->next;
vim_regfree(ap->reg_prog); vim_regfree(ap->reg_prog);
free(ap); xfree(ap);
} else } else
prev_ap = &(ap->next); prev_ap = &(ap->next);
} }
@ -5445,7 +5445,7 @@ static void au_del_group(char_u *name)
if (i == AUGROUP_ERROR) /* the group doesn't exist */ if (i == AUGROUP_ERROR) /* the group doesn't exist */
EMSG2(_("E367: No such group: \"%s\""), name); EMSG2(_("E367: No such group: \"%s\""), name);
else { else {
free(AUGROUP_NAME(i)); xfree(AUGROUP_NAME(i));
AUGROUP_NAME(i) = NULL; AUGROUP_NAME(i) = NULL;
} }
} }
@ -5637,7 +5637,7 @@ char_u *au_event_disable(char *what)
else else
STRCAT(new_ei, what); STRCAT(new_ei, what);
set_string_option_direct((char_u *)"ei", -1, new_ei, OPT_FREE, SID_NONE); set_string_option_direct((char_u *)"ei", -1, new_ei, OPT_FREE, SID_NONE);
free(new_ei); xfree(new_ei);
return save_ei; return save_ei;
} }
@ -5647,7 +5647,7 @@ void au_event_restore(char_u *old_ei)
if (old_ei != NULL) { if (old_ei != NULL) {
set_string_option_direct((char_u *)"ei", -1, old_ei, set_string_option_direct((char_u *)"ei", -1, old_ei,
OPT_FREE, SID_NONE); OPT_FREE, SID_NONE);
free(old_ei); xfree(old_ei);
} }
} }
@ -5782,8 +5782,8 @@ void do_autocmd(char_u *arg, int forceit)
} }
if (need_free) if (need_free)
free(cmd); xfree(cmd);
free(envpat); xfree(envpat);
} }
/* /*
@ -5807,7 +5807,7 @@ static int au_get_grouparg(char_u **argp)
group = AUGROUP_ALL; /* no match, use all groups */ group = AUGROUP_ALL; /* no match, use all groups */
else else
*argp = skipwhite(p); /* match, skip over group name */ *argp = skipwhite(p); /* match, skip over group name */
free(group_name); xfree(group_name);
} }
return group; return group;
} }
@ -5984,10 +5984,10 @@ static int do_autocmd_event(event_T event, char_u *pat, int nested, char_u *cmd,
&ap->allow_dirs, TRUE); &ap->allow_dirs, TRUE);
if (reg_pat != NULL) if (reg_pat != NULL)
ap->reg_prog = vim_regcomp(reg_pat, RE_MAGIC); ap->reg_prog = vim_regcomp(reg_pat, RE_MAGIC);
free(reg_pat); xfree(reg_pat);
if (reg_pat == NULL || ap->reg_prog == NULL) { if (reg_pat == NULL || ap->reg_prog == NULL) {
free(ap->pat); xfree(ap->pat);
free(ap); xfree(ap);
return FAIL; return FAIL;
} }
} }
@ -6186,7 +6186,7 @@ aucmd_prepbuf (
/* Make sure w_localdir and globaldir are NULL to avoid a chdir() in /* Make sure w_localdir and globaldir are NULL to avoid a chdir() in
* win_enter_ext(). */ * win_enter_ext(). */
free(aucmd_win->w_localdir); xfree(aucmd_win->w_localdir);
aucmd_win->w_localdir = NULL; aucmd_win->w_localdir = NULL;
aco->globaldir = globaldir; aco->globaldir = globaldir;
globaldir = NULL; globaldir = NULL;
@ -6262,7 +6262,7 @@ win_found:
hash_init(&aucmd_win->w_vars->dv_hashtab); /* re-use the hashtab */ hash_init(&aucmd_win->w_vars->dv_hashtab); /* re-use the hashtab */
curbuf = curwin->w_buffer; curbuf = curwin->w_buffer;
free(globaldir); xfree(globaldir);
globaldir = aco->globaldir; globaldir = aco->globaldir;
/* the buffer contents may have changed */ /* the buffer contents may have changed */
@ -6599,7 +6599,7 @@ apply_autocmds_group (
fname = FullName_save(fname, FALSE); fname = FullName_save(fname, FALSE);
} }
if (fname == NULL) { /* out of memory */ if (fname == NULL) { /* out of memory */
free(sfname); xfree(sfname);
retval = FALSE; retval = FALSE;
goto BYPASS_AU; goto BYPASS_AU;
} }
@ -6705,10 +6705,10 @@ apply_autocmds_group (
autocmd_busy = save_autocmd_busy; autocmd_busy = save_autocmd_busy;
filechangeshell_busy = FALSE; filechangeshell_busy = FALSE;
autocmd_nested = save_autocmd_nested; autocmd_nested = save_autocmd_nested;
free(sourcing_name); xfree(sourcing_name);
sourcing_name = save_sourcing_name; sourcing_name = save_sourcing_name;
sourcing_lnum = save_sourcing_lnum; sourcing_lnum = save_sourcing_lnum;
free(autocmd_fname); xfree(autocmd_fname);
autocmd_fname = save_autocmd_fname; autocmd_fname = save_autocmd_fname;
autocmd_fname_full = save_autocmd_fname_full; autocmd_fname_full = save_autocmd_fname_full;
autocmd_bufnr = save_autocmd_bufnr; autocmd_bufnr = save_autocmd_bufnr;
@ -6717,8 +6717,8 @@ apply_autocmds_group (
restore_funccal(save_funccalp); restore_funccal(save_funccalp);
if (do_profiling == PROF_YES) if (do_profiling == PROF_YES)
prof_child_exit(&wait_time); prof_child_exit(&wait_time);
free(fname); xfree(fname);
free(sfname); xfree(sfname);
--nesting; /* see matching increment above */ --nesting; /* see matching increment above */
// When stopping to execute autocommands, restore the search patterns and // When stopping to execute autocommands, restore the search patterns and
@ -6730,12 +6730,12 @@ apply_autocmds_group (
did_filetype = FALSE; did_filetype = FALSE;
while (au_pending_free_buf != NULL) { while (au_pending_free_buf != NULL) {
buf_T *b = au_pending_free_buf->b_next; buf_T *b = au_pending_free_buf->b_next;
free(au_pending_free_buf); xfree(au_pending_free_buf);
au_pending_free_buf = b; au_pending_free_buf = b;
} }
while (au_pending_free_win != NULL) { while (au_pending_free_win != NULL) {
win_T *w = au_pending_free_win->w_next; win_T *w = au_pending_free_win->w_next;
free(au_pending_free_win); xfree(au_pending_free_win);
au_pending_free_win = w; au_pending_free_win = w;
} }
} }
@ -6806,7 +6806,7 @@ auto_next_pat (
char_u *name; char_u *name;
char *s; char *s;
free(sourcing_name); xfree(sourcing_name);
sourcing_name = NULL; sourcing_name = NULL;
for (ap = apc->curpat; ap != NULL && !got_int; ap = ap->next) { for (ap = apc->curpat; ap != NULL && !got_int; ap = ap->next) {
@ -6942,9 +6942,9 @@ int has_autocmd(event_T event, char_u *sfname, buf_T *buf)
break; break;
} }
free(fname); xfree(fname);
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
free(sfname); xfree(sfname);
#endif #endif
return retval; return retval;
@ -7124,7 +7124,7 @@ int au_exists(char_u *arg)
} }
theend: theend:
free(arg_save); xfree(arg_save);
return retval; return retval;
} }
@ -7203,7 +7203,7 @@ int match_file_list(char_u *list, char_u *sfname, char_u *ffname)
break; break;
match = match_file_pat(regpat, NULL, ffname, sfname, match = match_file_pat(regpat, NULL, ffname, sfname,
tail, (int)allow_dirs); tail, (int)allow_dirs);
free(regpat); xfree(regpat);
if (match) if (match)
return TRUE; return TRUE;
} }
@ -7399,7 +7399,7 @@ file_pat_to_reg_pat (
EMSG(_("E219: Missing {.")); EMSG(_("E219: Missing {."));
else else
EMSG(_("E220: Missing }.")); EMSG(_("E220: Missing }."));
free(reg_pat); xfree(reg_pat);
reg_pat = NULL; reg_pat = NULL;
} }
return reg_pat; return reg_pat;

View File

@ -1326,7 +1326,7 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive)
sizeof(fold_T) * (size_t)(gap->ga_len - (idx + 1))); sizeof(fold_T) * (size_t)(gap->ga_len - (idx + 1)));
/* move the contained folds one level up */ /* move the contained folds one level up */
memmove(fp, nfp, sizeof(fold_T) * (size_t)moved); memmove(fp, nfp, sizeof(fold_T) * (size_t)moved);
free(nfp); xfree(nfp);
gap->ga_len += moved - 1; gap->ga_len += moved - 1;
} }
} }
@ -1760,7 +1760,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume,
} }
if (*p != NUL) { if (*p != NUL) {
p = transstr(text); p = transstr(text);
free(text); xfree(text);
text = p; text = p;
} }
} }

View File

@ -24,7 +24,7 @@
/// Clear an allocated growing array. /// Clear an allocated growing array.
void ga_clear(garray_T *gap) void ga_clear(garray_T *gap)
{ {
free(gap->ga_data); xfree(gap->ga_data);
// Initialize growing array without resetting itemsize or growsize // Initialize growing array without resetting itemsize or growsize
gap->ga_data = NULL; gap->ga_data = NULL;
@ -114,7 +114,7 @@ void ga_remove_duplicate_strings(garray_T *gap)
// loop over the growing array in reverse // loop over the growing array in reverse
for (int i = gap->ga_len - 1; i > 0; i--) { for (int i = gap->ga_len - 1; i > 0; i--) {
if (fnamecmp(fnames[i - 1], fnames[i]) == 0) { if (fnamecmp(fnames[i - 1], fnames[i]) == 0) {
free(fnames[i]); xfree(fnames[i]);
// close the gap (move all strings one slot lower) // close the gap (move all strings one slot lower)
for (int j = i + 1; j < gap->ga_len; j++) { for (int j = i + 1; j < gap->ga_len; j++) {

View File

@ -61,7 +61,7 @@ static inline void *ga_append_via_ptr(garray_T *gap, size_t item_size)
ga_clear(_gap); \ ga_clear(_gap); \
} while (false) } while (false)
#define FREE_PTR_PTR(ptr) free(*(ptr)) #define FREE_PTR_PTR(ptr) xfree(*(ptr))
/// Call `free` for every pointer stored in the garray and then frees the /// Call `free` for every pointer stored in the garray and then frees the
/// garray. /// garray.

View File

@ -167,7 +167,7 @@ void free_buff(buffheader_T *buf)
for (p = buf->bh_first.b_next; p != NULL; p = np) { for (p = buf->bh_first.b_next; p != NULL; p = np) {
np = p->b_next; np = p->b_next;
free(p); xfree(p);
} }
buf->bh_first.b_next = NULL; buf->bh_first.b_next = NULL;
} }
@ -365,7 +365,7 @@ static int read_readbuf(buffheader_T *buf, int advance)
if (advance) { if (advance) {
if (curr->b_str[++buf->bh_index] == NUL) { if (curr->b_str[++buf->bh_index] == NUL) {
buf->bh_first.b_next = curr->b_next; buf->bh_first.b_next = curr->b_next;
free(curr); xfree(curr);
buf->bh_index = 0; buf->bh_index = 0;
} }
} }
@ -495,7 +495,7 @@ void saveRedobuff(void)
s = get_buffcont(&save_redobuff, FALSE); s = get_buffcont(&save_redobuff, FALSE);
if (s != NULL) { if (s != NULL) {
add_buff(&redobuff, s, -1L); add_buff(&redobuff, s, -1L);
free(s); xfree(s);
} }
} }
} }
@ -904,7 +904,7 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, int silent)
typebuf.tb_buf + typebuf.tb_off + offset, typebuf.tb_buf + typebuf.tb_off + offset,
(size_t)(typebuf.tb_len - offset + 1)); (size_t)(typebuf.tb_len - offset + 1));
if (typebuf.tb_buf != typebuf_init) if (typebuf.tb_buf != typebuf_init)
free(typebuf.tb_buf); xfree(typebuf.tb_buf);
typebuf.tb_buf = s1; typebuf.tb_buf = s1;
memmove(s2 + newoff, typebuf.tb_noremap + typebuf.tb_off, memmove(s2 + newoff, typebuf.tb_noremap + typebuf.tb_off,
@ -913,7 +913,7 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, int silent)
typebuf.tb_noremap + typebuf.tb_off + offset, typebuf.tb_noremap + typebuf.tb_off + offset,
(size_t)(typebuf.tb_len - offset)); (size_t)(typebuf.tb_len - offset));
if (typebuf.tb_noremap != noremapbuf_init) if (typebuf.tb_noremap != noremapbuf_init)
free(typebuf.tb_noremap); xfree(typebuf.tb_noremap);
typebuf.tb_noremap = s2; typebuf.tb_noremap = s2;
typebuf.tb_off = newoff; typebuf.tb_off = newoff;
@ -1162,11 +1162,11 @@ void free_typebuf(void)
if (typebuf.tb_buf == typebuf_init) if (typebuf.tb_buf == typebuf_init)
EMSG2(_(e_intern2), "Free typebuf 1"); EMSG2(_(e_intern2), "Free typebuf 1");
else else
free(typebuf.tb_buf); xfree(typebuf.tb_buf);
if (typebuf.tb_noremap == noremapbuf_init) if (typebuf.tb_noremap == noremapbuf_init)
EMSG2(_(e_intern2), "Free typebuf 2"); EMSG2(_(e_intern2), "Free typebuf 2");
else else
free(typebuf.tb_noremap); xfree(typebuf.tb_noremap);
} }
/* /*
@ -2068,10 +2068,10 @@ static int vgetorpeek(int advance)
i = ins_typebuf(s, noremap, i = ins_typebuf(s, noremap,
0, TRUE, cmd_silent || save_m_silent); 0, TRUE, cmd_silent || save_m_silent);
if (save_m_expr) if (save_m_expr)
free(s); xfree(s);
} }
free(save_m_keys); xfree(save_m_keys);
free(save_m_str); xfree(save_m_str);
if (i == FAIL) { if (i == FAIL) {
c = -1; c = -1;
break; break;
@ -2906,9 +2906,9 @@ do_map (
} else { /* new rhs for existing entry */ } else { /* new rhs for existing entry */
mp->m_mode &= ~mode; /* remove mode bits */ mp->m_mode &= ~mode; /* remove mode bits */
if (mp->m_mode == 0 && !did_it) { /* reuse entry */ if (mp->m_mode == 0 && !did_it) { /* reuse entry */
free(mp->m_str); xfree(mp->m_str);
mp->m_str = vim_strsave(rhs); mp->m_str = vim_strsave(rhs);
free(mp->m_orig_str); xfree(mp->m_orig_str);
mp->m_orig_str = vim_strsave(orig_rhs); mp->m_orig_str = vim_strsave(orig_rhs);
mp->m_noremap = noremap; mp->m_noremap = noremap;
mp->m_nowait = nowait; mp->m_nowait = nowait;
@ -2998,8 +2998,8 @@ do_map (
} }
theend: theend:
free(keys_buf); xfree(keys_buf);
free(arg_buf); xfree(arg_buf);
return retval; return retval;
} }
@ -3012,11 +3012,11 @@ static void map_free(mapblock_T **mpp)
mapblock_T *mp; mapblock_T *mp;
mp = *mpp; mp = *mpp;
free(mp->m_keys); xfree(mp->m_keys);
free(mp->m_str); xfree(mp->m_str);
free(mp->m_orig_str); xfree(mp->m_orig_str);
*mpp = mp->m_next; *mpp = mp->m_next;
free(mp); xfree(mp);
} }
/* /*
@ -3211,7 +3211,7 @@ showmap (
if (mapchars != NULL) { if (mapchars != NULL) {
msg_puts(mapchars); msg_puts(mapchars);
len = (int)STRLEN(mapchars); len = (int)STRLEN(mapchars);
free(mapchars); xfree(mapchars);
} }
while (++len <= 3) while (++len <= 3)
@ -3246,7 +3246,7 @@ showmap (
char_u *s = vim_strsave(mp->m_str); char_u *s = vim_strsave(mp->m_str);
vim_unescape_csi(s); vim_unescape_csi(s);
msg_outtrans_special(s, FALSE); msg_outtrans_special(s, FALSE);
free(s); xfree(s);
} }
if (p_verbose > 0) if (p_verbose > 0)
last_set_msg(mp->m_script_ID); last_set_msg(mp->m_script_ID);
@ -3285,7 +3285,7 @@ int map_to_exists(char_u *str, char_u *modechars, int abbr)
mode |= CMDLINE; mode |= CMDLINE;
retval = map_to_exists_mode(rhs, mode, abbr); retval = map_to_exists_mode(rhs, mode, abbr);
free(buf); xfree(buf);
return retval; return retval;
} }
@ -3469,7 +3469,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file)
p = NULL; p = NULL;
} }
} }
free(p); xfree(p);
} }
} /* for (mp) */ } /* for (mp) */
} /* for (hash) */ } /* for (hash) */
@ -3499,7 +3499,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file)
if (STRCMP(*ptr1, *ptr2)) if (STRCMP(*ptr1, *ptr2))
*++ptr1 = *ptr2++; *++ptr1 = *ptr2++;
else { else {
free(*ptr2++); xfree(*ptr2++);
count--; count--;
} }
} }
@ -3617,7 +3617,7 @@ int check_abbr(int c, char_u *ptr, int col, int mincol)
&& qlen == len && qlen == len
&& !STRNCMP(q, ptr, (size_t)len); && !STRNCMP(q, ptr, (size_t)len);
if (q != mp->m_keys) { if (q != mp->m_keys) {
free(q); xfree(q);
} }
if (match) { if (match) {
break; break;
@ -3669,7 +3669,7 @@ int check_abbr(int c, char_u *ptr, int col, int mincol)
/* no abbrev. for these chars */ /* no abbrev. for these chars */
typebuf.tb_no_abbr_cnt += (int)STRLEN(s) + j + 1; typebuf.tb_no_abbr_cnt += (int)STRLEN(s) + j + 1;
if (mp->m_expr) if (mp->m_expr)
free(s); xfree(s);
} }
tb[0] = Ctrl_H; tb[0] = Ctrl_H;
@ -3725,13 +3725,13 @@ eval_map_expr (
msg_row = save_msg_row; msg_row = save_msg_row;
restore_cmdline_alloc(save_cmd); restore_cmdline_alloc(save_cmd);
free(expr); xfree(expr);
if (p == NULL) if (p == NULL)
return NULL; return NULL;
/* Escape CSI in the result to be able to use the string as typeahead. */ /* Escape CSI in the result to be able to use the string as typeahead. */
res = vim_strsave_escape_csi(p); res = vim_strsave_escape_csi(p);
free(p); xfree(p);
return res; return res;
} }
@ -4171,7 +4171,7 @@ void add_map(char_u *map, int mode)
p_cpo = (char_u *)""; /* Allow <> notation */ p_cpo = (char_u *)""; /* Allow <> notation */
s = vim_strsave(map); s = vim_strsave(map);
(void)do_map(0, s, mode, FALSE); (void)do_map(0, s, mode, FALSE);
free(s); xfree(s);
p_cpo = cpo_save; p_cpo = cpo_save;
} }

View File

@ -551,7 +551,7 @@ static void prt_header(prt_settings_T *psettings, int pagenum, linenr_T lnum)
p += l; p += l;
} }
free(tbuf); xfree(tbuf);
if (psettings->do_syntax) if (psettings->do_syntax)
/* Set colors for next character. */ /* Set colors for next character. */
@ -1539,7 +1539,7 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource)
retval = (do_in_runtimepath(buffer, FALSE, prt_resource_name, retval = (do_in_runtimepath(buffer, FALSE, prt_resource_name,
resource->filename) resource->filename)
&& resource->filename[0] != NUL); && resource->filename[0] != NUL);
free(buffer); xfree(buffer);
return retval; return retval;
} }
@ -1921,7 +1921,7 @@ void mch_print_cleanup(void)
*/ */
for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) { for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) {
if (prt_ps_mb_font.ps_fontname[i] != NULL) if (prt_ps_mb_font.ps_fontname[i] != NULL)
free(prt_ps_mb_font.ps_fontname[i]); xfree(prt_ps_mb_font.ps_fontname[i]);
prt_ps_mb_font.ps_fontname[i] = NULL; prt_ps_mb_font.ps_fontname[i] = NULL;
} }
} }
@ -1936,7 +1936,7 @@ void mch_print_cleanup(void)
prt_file_error = FALSE; prt_file_error = FALSE;
} }
if (prt_ps_file_name != NULL) { if (prt_ps_file_name != NULL) {
free(prt_ps_file_name); xfree(prt_ps_file_name);
prt_ps_file_name = NULL; prt_ps_file_name = NULL;
} }
} }
@ -2342,7 +2342,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
p = expand_env_save(psettings->outfile); p = expand_env_save(psettings->outfile);
if (p != NULL) { if (p != NULL) {
prt_ps_fd = mch_fopen((char *)p, WRITEBIN); prt_ps_fd = mch_fopen((char *)p, WRITEBIN);
free(p); xfree(p);
} }
} }
if (prt_ps_fd == NULL) { if (prt_ps_fd == NULL) {
@ -3032,7 +3032,7 @@ int mch_print_text_out(char_u *p, size_t len)
/* Need to free any translated characters */ /* Need to free any translated characters */
if (prt_do_conv) if (prt_do_conv)
free(p); xfree(p);
prt_text_run += char_width; prt_text_run += char_width;
prt_pos_x += char_width; prt_pos_x += char_width;

View File

@ -53,7 +53,7 @@ void hash_init(hashtab_T *ht)
void hash_clear(hashtab_T *ht) void hash_clear(hashtab_T *ht)
{ {
if (ht->ht_array != ht->ht_smallarray) { if (ht->ht_array != ht->ht_smallarray) {
free(ht->ht_array); xfree(ht->ht_array);
} }
} }
@ -65,7 +65,7 @@ void hash_clear_all(hashtab_T *ht, unsigned int off)
size_t todo = ht->ht_used; size_t todo = ht->ht_used;
for (hashitem_T *hi = ht->ht_array; todo > 0; ++hi) { for (hashitem_T *hi = ht->ht_array; todo > 0; ++hi) {
if (!HASHITEM_EMPTY(hi)) { if (!HASHITEM_EMPTY(hi)) {
free(hi->hi_key - off); xfree(hi->hi_key - off);
todo--; todo--;
} }
} }
@ -351,7 +351,7 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems)
} }
if (ht->ht_array != ht->ht_smallarray) { if (ht->ht_array != ht->ht_smallarray) {
free(ht->ht_array); xfree(ht->ht_array);
} }
ht->ht_array = newarray; ht->ht_array = newarray;
ht->ht_mask = newmask; ht->ht_mask = newmask;

View File

@ -433,7 +433,7 @@ static void cs_stat_emsg(char *fname)
(void)sprintf(buf, stat_emsg, fname, errno); (void)sprintf(buf, stat_emsg, fname, errno);
(void)EMSG(buf); (void)EMSG(buf);
free(buf); xfree(buf);
} }
@ -470,7 +470,7 @@ cs_add_common (
if (fname == NULL) if (fname == NULL)
goto add_err; goto add_err;
fname = (char *)vim_strnsave((char_u *)fname, len); fname = (char *)vim_strnsave((char_u *)fname, len);
free(fbuf); xfree(fbuf);
FileInfo file_info; FileInfo file_info;
bool file_info_ok = os_fileinfo(fname, &file_info); bool file_info_ok = os_fileinfo(fname, &file_info);
if (!file_info_ok) { if (!file_info_ok) {
@ -538,15 +538,15 @@ staterr:
} }
} }
free(fname); xfree(fname);
free(fname2); xfree(fname2);
free(ppath); xfree(ppath);
return CSCOPE_SUCCESS; return CSCOPE_SUCCESS;
add_err: add_err:
free(fname2); xfree(fname2);
free(fname); xfree(fname);
free(ppath); xfree(ppath);
return CSCOPE_FAILURE; return CSCOPE_FAILURE;
} /* cs_add_common */ } /* cs_add_common */
@ -605,7 +605,7 @@ static int cs_cnt_matches(int idx)
cs_reading_emsg(idx); cs_reading_emsg(idx);
free(buf); xfree(buf);
return -1; return -1;
} }
@ -636,7 +636,7 @@ static int cs_cnt_matches(int idx)
break; break;
} }
free(buf); xfree(buf);
return nlines; return nlines;
} /* cs_cnt_matches */ } /* cs_cnt_matches */
@ -805,9 +805,9 @@ err_closing:
} }
# ifdef UNIX # ifdef UNIX
/* on Win32 we still need prog */ /* on Win32 we still need prog */
free(prog); xfree(prog);
# endif # endif
free(ppath); xfree(ppath);
#if defined(UNIX) #if defined(UNIX)
# if defined(HAVE_SETSID) || defined(HAVE_SETPGID) # if defined(HAVE_SETSID) || defined(HAVE_SETPGID)
@ -852,8 +852,8 @@ err_closing:
si.hStdInput = stdin_rd; si.hStdInput = stdin_rd;
created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE,
NULL, NULL, &si, &pi); NULL, NULL, &si, &pi);
free(prog); xfree(prog);
free(cmd); xfree(cmd);
if (!created) { if (!created) {
PERROR(_("cs_create_connection exec failed")); PERROR(_("cs_create_connection exec failed"));
@ -982,7 +982,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us
sprintf(buf, nf, *qfpos, *(qfpos-1)); sprintf(buf, nf, *qfpos, *(qfpos-1));
(void)EMSG(buf); (void)EMSG(buf);
free(buf); xfree(buf);
return FALSE; return FALSE;
} }
@ -1022,22 +1022,22 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us
if (nummatches[i] == 0) if (nummatches[i] == 0)
(void)cs_read_prompt(i); (void)cs_read_prompt(i);
} }
free(cmd); xfree(cmd);
if (totmatches == 0) { if (totmatches == 0) {
char *nf = _("E259: no matches found for cscope query %s of %s"); char *nf = _("E259: no matches found for cscope query %s of %s");
char *buf; char *buf;
if (!verbose) { if (!verbose) {
free(nummatches); xfree(nummatches);
return FALSE; return FALSE;
} }
buf = xmalloc(strlen(opt) + strlen(pat) + strlen(nf)); buf = xmalloc(strlen(opt) + strlen(pat) + strlen(nf));
sprintf(buf, nf, opt, pat); sprintf(buf, nf, opt, pat);
(void)EMSG(buf); (void)EMSG(buf);
free(buf); xfree(buf);
free(nummatches); xfree(nummatches);
return FALSE; return FALSE;
} }
@ -1079,8 +1079,8 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us
} }
} }
os_remove((char *)tmp); os_remove((char *)tmp);
free(tmp); xfree(tmp);
free(nummatches); xfree(nummatches);
return TRUE; return TRUE;
} else { } else {
char **matches = NULL, **contexts = NULL; char **matches = NULL, **contexts = NULL;
@ -1089,7 +1089,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us
/* read output */ /* read output */
cs_fill_results((char *)pat, totmatches, nummatches, &matches, cs_fill_results((char *)pat, totmatches, nummatches, &matches,
&contexts, &matched); &contexts, &matched);
free(nummatches); xfree(nummatches);
if (matches == NULL) if (matches == NULL)
return FALSE; return FALSE;
@ -1424,12 +1424,12 @@ static char *cs_manage_matches(char **matches, char **contexts, int totmatches,
if (mp != NULL) { if (mp != NULL) {
if (cnt > 0) if (cnt > 0)
while (cnt--) { while (cnt--) {
free(mp[cnt]); xfree(mp[cnt]);
if (cp != NULL) if (cp != NULL)
free(cp[cnt]); xfree(cp[cnt]);
} }
free(mp); xfree(mp);
free(cp); xfree(cp);
} }
mp = NULL; mp = NULL;
cp = NULL; cp = NULL;
@ -1537,14 +1537,14 @@ static void cs_file_results(FILE *f, int *nummatches_a)
else else
fprintf(f, "%s\t%s\t%s %s\n", fullname, slno, context, search); fprintf(f, "%s\t%s\t%s %s\n", fullname, slno, context, search);
free(context); xfree(context);
free(fullname); xfree(fullname);
} /* for all matches */ } /* for all matches */
(void)cs_read_prompt(i); (void)cs_read_prompt(i);
} /* for all cscope connections */ } /* for all cscope connections */
free(buf); xfree(buf);
} }
/* /*
@ -1583,7 +1583,7 @@ static void cs_fill_results(char *tagstr, int totmatches, int *nummatches_a, cha
matches[totsofar] = cs_make_vim_style_matches(fullname, slno, search, matches[totsofar] = cs_make_vim_style_matches(fullname, slno, search,
tagstr); tagstr);
free(fullname); xfree(fullname);
if (strcmp(cntx, "<global>") == 0) if (strcmp(cntx, "<global>") == 0)
cntxts[totsofar] = NULL; cntxts[totsofar] = NULL;
@ -1601,16 +1601,16 @@ static void cs_fill_results(char *tagstr, int totmatches, int *nummatches_a, cha
if (totsofar == 0) { if (totsofar == 0) {
/* No matches, free the arrays and return NULL in "*matches_p". */ /* No matches, free the arrays and return NULL in "*matches_p". */
free(matches); xfree(matches);
matches = NULL; matches = NULL;
free(cntxts); xfree(cntxts);
cntxts = NULL; cntxts = NULL;
} }
*matched = totsofar; *matched = totsofar;
*matches_p = matches; *matches_p = matches;
*cntxts_p = cntxts; *cntxts_p = cntxts;
free(buf); xfree(buf);
} /* cs_fill_results */ } /* cs_fill_results */
@ -1661,7 +1661,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches)
(void)sprintf(buf, cstag_msg, ptag); (void)sprintf(buf, cstag_msg, ptag);
MSG_PUTS_ATTR(buf, hl_attr(HLF_T)); MSG_PUTS_ATTR(buf, hl_attr(HLF_T));
free(tbuf); xfree(tbuf);
MSG_PUTS_ATTR(_("\n # line"), hl_attr(HLF_T)); /* strlen is 7 */ MSG_PUTS_ATTR(_("\n # line"), hl_attr(HLF_T)); /* strlen is 7 */
msg_advance(msg_col + 2); msg_advance(msg_col + 2);
@ -1727,7 +1727,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches)
MSG_PUTS_LONG(extra); MSG_PUTS_LONG(extra);
} }
free(tbuf); /* only after printing extra due to strtok use */ xfree(tbuf); /* only after printing extra due to strtok use */
if (msg_col) if (msg_col)
msg_putchar('\n'); msg_putchar('\n');
@ -1741,7 +1741,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches)
num++; num++;
} /* for all matches */ } /* for all matches */
free(buf); xfree(buf);
} /* cs_print_tags_priv */ } /* cs_print_tags_priv */
@ -1806,7 +1806,7 @@ static int cs_read_prompt(int i)
else if (p_csverbose) else if (p_csverbose)
cs_reading_emsg(i); /* don't have additional information */ cs_reading_emsg(i); /* don't have additional information */
cs_release_csp(i, TRUE); cs_release_csp(i, TRUE);
free(buf); xfree(buf);
return CSCOPE_FAILURE; return CSCOPE_FAILURE;
} }
@ -1821,7 +1821,7 @@ static int cs_read_prompt(int i)
break; /* did find the prompt */ break; /* did find the prompt */
} }
free(buf); xfree(buf);
return CSCOPE_SUCCESS; return CSCOPE_SUCCESS;
} }
@ -1947,9 +1947,9 @@ static void cs_release_csp(int i, int freefnpp)
(void)fclose(csinfo[i].to_fp); (void)fclose(csinfo[i].to_fp);
if (freefnpp) { if (freefnpp) {
free(csinfo[i].fname); xfree(csinfo[i].fname);
free(csinfo[i].ppath); xfree(csinfo[i].ppath);
free(csinfo[i].flags); xfree(csinfo[i].flags);
} }
clear_csinfo(i); clear_csinfo(i);
@ -1996,13 +1996,13 @@ static int cs_reset(exarg_T *eap)
MSG_PUTS_ATTR(buf, hl_attr(HLF_R)); MSG_PUTS_ATTR(buf, hl_attr(HLF_R));
} }
} }
free(dblist[i]); xfree(dblist[i]);
free(pplist[i]); xfree(pplist[i]);
free(fllist[i]); xfree(fllist[i]);
} }
free(dblist); xfree(dblist);
free(pplist); xfree(pplist);
free(fllist); xfree(fllist);
if (p_csverbose) if (p_csverbose)
MSG_ATTR(_("All cscope databases reset"), hl_attr(HLF_R) | MSG_HIST); MSG_ATTR(_("All cscope databases reset"), hl_attr(HLF_R) | MSG_HIST);
@ -2061,7 +2061,7 @@ static char *cs_resolve_file(int i, char *name)
fullname = xstrdup(name); fullname = xstrdup(name);
} }
free(csdir); xfree(csdir);
return fullname; return fullname;
} }
@ -2109,7 +2109,7 @@ void cs_end(void)
for (i = 0; i < csinfo_size; i++) for (i = 0; i < csinfo_size; i++)
cs_release_csp(i, TRUE); cs_release_csp(i, TRUE);
free(csinfo); xfree(csinfo);
csinfo_size = 0; csinfo_size = 0;
} }

View File

@ -297,7 +297,7 @@ int set_indent(int size, int flags)
} }
retval = true; retval = true;
} else { } else {
free(newline); xfree(newline);
} }
curwin->w_cursor.col = ind_len; curwin->w_cursor.col = ind_len;
return retval; return retval;

View File

@ -136,7 +136,7 @@ bool cin_is_cinword(char_u *line)
} }
} }
free(cinw_buf); xfree(cinw_buf);
return retval; return retval;
} }
@ -3280,7 +3280,7 @@ theend:
/* put the cursor back where it belongs */ /* put the cursor back where it belongs */
curwin->w_cursor = cur_curpos; curwin->w_cursor = cur_curpos;
free(linecopy); xfree(linecopy);
if (amount < 0) if (amount < 0)
return 0; return 0;

View File

@ -181,7 +181,7 @@ typedef khint_t khiter_t;
#define krealloc(P,Z) xrealloc(P,Z) #define krealloc(P,Z) xrealloc(P,Z)
#endif #endif
#ifndef kfree #ifndef kfree
#define kfree(P) free(P) #define kfree(P) xfree(P)
#endif #endif
static const double __ac_HASH_UPPER = 0.77; static const double __ac_HASH_UPPER = 0.77;

View File

@ -44,9 +44,9 @@
static inline void kmp_destroy_##name(kmp_##name##_t *mp) { \ static inline void kmp_destroy_##name(kmp_##name##_t *mp) { \
size_t k; \ size_t k; \
for (k = 0; k < mp->n; ++k) { \ for (k = 0; k < mp->n; ++k) { \
kmpfree_f(mp->buf[k]); free(mp->buf[k]); \ kmpfree_f(mp->buf[k]); xfree(mp->buf[k]); \
} \ } \
free(mp->buf); free(mp); \ xfree(mp->buf); xfree(mp); \
} \ } \
static inline kmptype_t *kmp_alloc_##name(kmp_##name##_t *mp) { \ static inline kmptype_t *kmp_alloc_##name(kmp_##name##_t *mp) { \
++mp->cnt; \ ++mp->cnt; \
@ -95,7 +95,7 @@
kmp_free(name, kl->mp, p); \ kmp_free(name, kl->mp, p); \
kmp_free(name, kl->mp, p); \ kmp_free(name, kl->mp, p); \
kmp_destroy(name, kl->mp); \ kmp_destroy(name, kl->mp); \
free(kl); \ xfree(kl); \
} \ } \
static inline kltype_t *kl_pushp_##name(kl_##name##_t *kl) { \ static inline kltype_t *kl_pushp_##name(kl_##name##_t *kl) { \
kl1_##name *q, *p = kmp_alloc(name, kl->mp); \ kl1_##name *q, *p = kmp_alloc(name, kl->mp); \

View File

@ -55,7 +55,7 @@ int main() {
#define kvec_t(type) struct { size_t size, capacity; type *items; } #define kvec_t(type) struct { size_t size, capacity; type *items; }
#define kv_init(v) ((v).size = (v).capacity = 0, (v).items = 0) #define kv_init(v) ((v).size = (v).capacity = 0, (v).items = 0)
#define kv_destroy(v) free((v).items) #define kv_destroy(v) xfree((v).items)
#define kv_A(v, i) ((v).items[(i)]) #define kv_A(v, i) ((v).items[(i)])
#define kv_pop(v) ((v).items[--(v).size]) #define kv_pop(v) ((v).items[--(v).size])
#define kv_size(v) ((v).size) #define kv_size(v) ((v).size)

View File

@ -644,7 +644,7 @@ main_loop (
// duplicates. // duplicates.
p = keep_msg; p = keep_msg;
msg_attr(p, keep_msg_attr); msg_attr(p, keep_msg_attr);
free(p); xfree(p);
} }
if (need_fileinfo) { /* show file info after redraw */ if (need_fileinfo) { /* show file info after redraw */
fileinfo(FALSE, TRUE, FALSE); fileinfo(FALSE, TRUE, FALSE);
@ -840,7 +840,7 @@ static void init_locale(void)
bindtextdomain(VIMPACKAGE, (char *)NameBuff); bindtextdomain(VIMPACKAGE, (char *)NameBuff);
} }
if (mustfree) if (mustfree)
free(p); xfree(p);
textdomain(VIMPACKAGE); textdomain(VIMPACKAGE);
} }
TIME_MSG("locale set"); TIME_MSG("locale set");
@ -1285,7 +1285,7 @@ scripterror:
char_u *r; char_u *r;
r = concat_fnames(p, path_tail(alist_name(&GARGLIST[0])), TRUE); r = concat_fnames(p, path_tail(alist_name(&GARGLIST[0])), TRUE);
free(p); xfree(p);
p = r; p = r;
} }
@ -1322,7 +1322,7 @@ scripterror:
p = xmalloc(STRLEN(parmp->commands[0]) + 3); p = xmalloc(STRLEN(parmp->commands[0]) + 3);
sprintf((char *)p, ":%s\r", parmp->commands[0]); sprintf((char *)p, ":%s\r", parmp->commands[0]);
set_vim_var_string(VV_SWAPCOMMAND, p, -1); set_vim_var_string(VV_SWAPCOMMAND, p, -1);
free(p); xfree(p);
} }
TIME_MSG("parsing arguments"); TIME_MSG("parsing arguments");
} }
@ -1753,7 +1753,7 @@ static void exe_commands(mparm_T *parmp)
for (i = 0; i < parmp->n_commands; ++i) { for (i = 0; i < parmp->n_commands; ++i) {
do_cmdline_cmd(parmp->commands[i]); do_cmdline_cmd(parmp->commands[i]);
if (parmp->cmds_tofree[i]) if (parmp->cmds_tofree[i])
free(parmp->commands[i]); xfree(parmp->commands[i]);
} }
sourcing_name = NULL; sourcing_name = NULL;
current_SID = 0; current_SID = 0;

View File

@ -45,7 +45,7 @@
void map_##T##_##U##_free(Map(T, U) *map) \ void map_##T##_##U##_free(Map(T, U) *map) \
{ \ { \
kh_destroy(T##_##U##_map, map->table); \ kh_destroy(T##_##U##_map, map->table); \
free(map); \ xfree(map); \
} \ } \
\ \
U map_##T##_##U##_get(Map(T, U) *map, T key) \ U map_##T##_##U##_get(Map(T, U) *map, T key) \

View File

@ -131,7 +131,7 @@ int setmark_pos(int c, pos_T *pos, int fnum)
i = c - 'A'; i = c - 'A';
namedfm[i].fmark.mark = *pos; namedfm[i].fmark.mark = *pos;
namedfm[i].fmark.fnum = fnum; namedfm[i].fmark.fnum = fnum;
free(namedfm[i].fname); xfree(namedfm[i].fname);
namedfm[i].fname = NULL; namedfm[i].fname = NULL;
return OK; return OK;
} }
@ -157,7 +157,7 @@ void setpcmark(void)
/* If jumplist is full: remove oldest entry */ /* If jumplist is full: remove oldest entry */
if (++curwin->w_jumplistlen > JUMPLISTSIZE) { if (++curwin->w_jumplistlen > JUMPLISTSIZE) {
curwin->w_jumplistlen = JUMPLISTSIZE; curwin->w_jumplistlen = JUMPLISTSIZE;
free(curwin->w_jumplist[0].fname); xfree(curwin->w_jumplist[0].fname);
for (i = 1; i < JUMPLISTSIZE; ++i) for (i = 1; i < JUMPLISTSIZE; ++i)
curwin->w_jumplist[i - 1] = curwin->w_jumplist[i]; curwin->w_jumplist[i - 1] = curwin->w_jumplist[i];
} }
@ -496,7 +496,7 @@ void fmarks_check_names(buf_T *buf)
} }
} }
free(name); xfree(name);
} }
static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf) static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf)
@ -505,7 +505,7 @@ static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf)
&& fm->fname != NULL && fm->fname != NULL
&& fnamecmp(name, fm->fname) == 0) { && fnamecmp(name, fm->fname) == 0) {
fm->fmark.fnum = buf->b_fnum; fm->fmark.fnum = buf->b_fnum;
free(fm->fname); xfree(fm->fname);
fm->fname = NULL; fm->fname = NULL;
} }
} }
@ -623,7 +623,7 @@ void do_marks(exarg_T *eap)
arg, &namedfm[i].fmark.mark, name, arg, &namedfm[i].fmark.mark, name,
namedfm[i].fmark.fnum == curbuf->b_fnum); namedfm[i].fmark.fnum == curbuf->b_fnum);
if (namedfm[i].fmark.fnum != 0) if (namedfm[i].fmark.fnum != 0)
free(name); xfree(name);
} }
} }
show_one_mark('"', arg, &curbuf->b_last_cursor, NULL, TRUE); show_one_mark('"', arg, &curbuf->b_last_cursor, NULL, TRUE);
@ -678,7 +678,7 @@ show_one_mark (
if (name != NULL) { if (name != NULL) {
msg_outtrans_attr(name, current ? hl_attr(HLF_D) : 0); msg_outtrans_attr(name, current ? hl_attr(HLF_D) : 0);
if (mustfree) if (mustfree)
free(name); xfree(name);
} }
} }
ui_flush(); /* show one line at a time */ ui_flush(); /* show one line at a time */
@ -735,7 +735,7 @@ void ex_delmarks(exarg_T *eap)
else else
n = i - 'A'; n = i - 'A';
namedfm[n].fmark.mark.lnum = 0; namedfm[n].fmark.mark.lnum = 0;
free(namedfm[n].fname); xfree(namedfm[n].fname);
namedfm[n].fname = NULL; namedfm[n].fname = NULL;
} }
} }
@ -777,7 +777,7 @@ void ex_jumps(exarg_T *eap)
msg_putchar('\n'); msg_putchar('\n');
if (got_int) { if (got_int) {
free(name); xfree(name);
break; break;
} }
sprintf((char *)IObuff, "%c %2d %5ld %4d ", sprintf((char *)IObuff, "%c %2d %5ld %4d ",
@ -790,7 +790,7 @@ void ex_jumps(exarg_T *eap)
msg_outtrans_attr(name, msg_outtrans_attr(name,
curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum
? hl_attr(HLF_D) : 0); ? hl_attr(HLF_D) : 0);
free(name); xfree(name);
os_breakcheck(); os_breakcheck();
} }
ui_flush(); ui_flush();
@ -824,7 +824,7 @@ void ex_changes(exarg_T *eap)
msg_outtrans(IObuff); msg_outtrans(IObuff);
name = mark_line(&curbuf->b_changelist[i], 17); name = mark_line(&curbuf->b_changelist[i], 17);
msg_outtrans_attr(name, hl_attr(HLF_D)); msg_outtrans_attr(name, hl_attr(HLF_D));
free(name); xfree(name);
os_breakcheck(); os_breakcheck();
} }
ui_flush(); ui_flush();
@ -1120,7 +1120,7 @@ static void cleanup_jumplist(void)
if (i >= curwin->w_jumplistlen) /* no duplicate */ if (i >= curwin->w_jumplistlen) /* no duplicate */
curwin->w_jumplist[to++] = curwin->w_jumplist[from]; curwin->w_jumplist[to++] = curwin->w_jumplist[from];
else else
free(curwin->w_jumplist[from].fname); xfree(curwin->w_jumplist[from].fname);
} }
if (curwin->w_jumplistidx == curwin->w_jumplistlen) if (curwin->w_jumplistidx == curwin->w_jumplistlen)
curwin->w_jumplistidx = to; curwin->w_jumplistidx = to;
@ -1151,7 +1151,7 @@ void free_jumplist(win_T *wp)
int i; int i;
for (i = 0; i < wp->w_jumplistlen; ++i) for (i = 0; i < wp->w_jumplistlen; ++i)
free(wp->w_jumplist[i].fname); xfree(wp->w_jumplist[i].fname);
} }
void set_last_cursor(win_T *win) void set_last_cursor(win_T *win)
@ -1167,7 +1167,7 @@ void free_all_marks(void)
for (i = 0; i < NMARKS + EXTRA_MARKS; i++) for (i = 0; i < NMARKS + EXTRA_MARKS; i++)
if (namedfm[i].fmark.mark.lnum != 0) if (namedfm[i].fmark.mark.lnum != 0)
free(namedfm[i].fname); xfree(namedfm[i].fname);
} }
#endif #endif
@ -1212,7 +1212,7 @@ int read_viminfo_filemark(vir_T *virp, int force)
fm->fmark.mark.coladd = 0; fm->fmark.mark.coladd = 0;
fm->fmark.fnum = 0; fm->fmark.fnum = 0;
str = skipwhite(str); str = skipwhite(str);
free(fm->fname); xfree(fm->fname);
fm->fname = viminfo_readstring(virp, (int)(str - virp->vir_line), fm->fname = viminfo_readstring(virp, (int)(str - virp->vir_line),
FALSE); FALSE);
} }
@ -1247,9 +1247,9 @@ void write_viminfo_filemarks(FILE *fp)
: (name != NULL : (name != NULL
&& STRCMP(name, namedfm[i].fname) == 0))) && STRCMP(name, namedfm[i].fname) == 0)))
break; break;
free(name); xfree(name);
free(namedfm[i].fname); xfree(namedfm[i].fname);
for (; i > NMARKS; --i) for (; i > NMARKS; --i)
namedfm[i] = namedfm[i - 1]; namedfm[i] = namedfm[i - 1];
namedfm[NMARKS].fmark.mark = curwin->w_cursor; namedfm[NMARKS].fmark.mark = curwin->w_cursor;
@ -1293,7 +1293,7 @@ static void write_one_filemark(FILE *fp, xfmark_T *fm, int c1, int c2)
} }
if (fm->fmark.fnum != 0) if (fm->fmark.fnum != 0)
free(name); xfree(name);
} }
/* /*
@ -1317,7 +1317,7 @@ int removable(char_u *name)
} }
} }
} }
free(name); xfree(name);
return retval; return retval;
} }
@ -1474,7 +1474,7 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags
count++; count++;
} }
} }
free(str); xfree(str);
pos.coladd = 0; pos.coladd = 0;
while (!(eof = viminfo_readline(virp)) && line[0] == TAB) { while (!(eof = viminfo_readline(virp)) && line[0] == TAB) {
@ -1520,5 +1520,5 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags
break; break;
} }
} }
free(name_buf); xfree(name_buf);
} }

View File

@ -523,7 +523,7 @@ char_u * mb_init(void)
convert_setup(&vimconv, p_enc, (char_u *)"utf-8"); convert_setup(&vimconv, p_enc, (char_u *)"utf-8");
vimconv.vc_fail = true; vimconv.vc_fail = true;
} }
free(p); xfree(p);
} }
#endif #endif
@ -549,7 +549,7 @@ char_u * mb_init(void)
*/ */
p = string_convert(&vimconv, (char_u *)buf, NULL); p = string_convert(&vimconv, (char_u *)buf, NULL);
if (p != NULL) { if (p != NULL) {
free(p); xfree(p);
n = 1; n = 1;
} else } else
n = 2; n = 2;
@ -3103,7 +3103,7 @@ void utf_find_illegal(void)
for (;; ) { for (;; ) {
p = get_cursor_pos_ptr(); p = get_cursor_pos_ptr();
if (vimconv.vc_type != CONV_NONE) { if (vimconv.vc_type != CONV_NONE) {
free(tofree); xfree(tofree);
tofree = string_convert(&vimconv, p, NULL); tofree = string_convert(&vimconv, p, NULL);
if (tofree == NULL) if (tofree == NULL)
break; break;
@ -3142,7 +3142,7 @@ void utf_find_illegal(void)
beep_flush(); beep_flush();
theend: theend:
free(tofree); xfree(tofree);
convert_setup(&vimconv, NULL, NULL); convert_setup(&vimconv, NULL, NULL);
} }
@ -3375,7 +3375,7 @@ char_u *enc_canonize(char_u *enc) FUNC_ATTR_NONNULL_RET
STRMOVE(r, p); STRMOVE(r, p);
} else if ((i = enc_alias_search(p)) >= 0) { } else if ((i = enc_alias_search(p)) >= 0) {
/* alias recognized, get canonical name */ /* alias recognized, get canonical name */
free(r); xfree(r);
r = vim_strsave((char_u *)enc_canon_table[i].name); r = vim_strsave((char_u *)enc_canon_table[i].name);
} }
return r; return r;
@ -3537,7 +3537,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, size_t slen,
p = xmalloc(len); p = xmalloc(len);
if (done > 0) if (done > 0)
memmove(p, result, done); memmove(p, result, done);
free(result); xfree(result);
result = p; result = p;
} }
@ -3582,7 +3582,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, size_t slen,
fromlen -= l; fromlen -= l;
} else if (ICONV_ERRNO != ICONV_E2BIG) { } else if (ICONV_ERRNO != ICONV_E2BIG) {
/* conversion failed */ /* conversion failed */
free(result); xfree(result);
result = NULL; result = NULL;
break; break;
} }
@ -3891,7 +3891,7 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr,
if (l_w == 0) { if (l_w == 0) {
/* Illegal utf-8 byte cannot be converted */ /* Illegal utf-8 byte cannot be converted */
free(retval); xfree(retval);
return NULL; return NULL;
} }
if (unconvlenp != NULL && l_w > len - i) { if (unconvlenp != NULL && l_w > len - i) {
@ -3925,7 +3925,7 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr,
if (c < 0x100) if (c < 0x100)
*d++ = c; *d++ = c;
else if (vcp->vc_fail) { else if (vcp->vc_fail) {
free(retval); xfree(retval);
return NULL; return NULL;
} else { } else {
*d++ = 0xbf; *d++ = 0xbf;

View File

@ -99,7 +99,7 @@ memfile_T *mf_open(char_u *fname, int flags)
mf_do_open(mfp, fname, flags); mf_do_open(mfp, fname, flags);
if (mfp->mf_fd < 0) { // fail if file could not be opened if (mfp->mf_fd < 0) { // fail if file could not be opened
free(mfp); xfree(mfp);
return NULL; return NULL;
} }
} }
@ -210,12 +210,12 @@ void mf_close(memfile_T *mfp, bool del_file)
mf_free_bhdr(hp); mf_free_bhdr(hp);
} }
while (mfp->mf_free_first != NULL) // free entries in free list while (mfp->mf_free_first != NULL) // free entries in free list
free(mf_rem_free(mfp)); xfree(mf_rem_free(mfp));
mf_hash_free(&mfp->mf_hash); mf_hash_free(&mfp->mf_hash);
mf_hash_free_all(&mfp->mf_trans); // free hashtable and its items mf_hash_free_all(&mfp->mf_trans); // free hashtable and its items
free(mfp->mf_fname); xfree(mfp->mf_fname);
free(mfp->mf_ffname); xfree(mfp->mf_ffname);
free(mfp); xfree(mfp);
} }
/// Close the swap file for a memfile. Used when 'swapfile' is reset. /// Close the swap file for a memfile. Used when 'swapfile' is reset.
@ -242,8 +242,8 @@ void mf_close_file(buf_T *buf, bool getlines)
if (mfp->mf_fname != NULL) { if (mfp->mf_fname != NULL) {
os_remove((char *)mfp->mf_fname); // delete the swap file os_remove((char *)mfp->mf_fname); // delete the swap file
free(mfp->mf_fname); xfree(mfp->mf_fname);
free(mfp->mf_ffname); xfree(mfp->mf_ffname);
mfp->mf_fname = NULL; mfp->mf_fname = NULL;
mfp->mf_ffname = NULL; mfp->mf_ffname = NULL;
} }
@ -302,7 +302,7 @@ bhdr_T *mf_new(memfile_T *mfp, bool negative, unsigned page_count)
} else { // use the number, remove entry from free list } else { // use the number, remove entry from free list
freep = mf_rem_free(mfp); freep = mf_rem_free(mfp);
hp->bh_bnum = freep->bh_bnum; hp->bh_bnum = freep->bh_bnum;
free(freep); xfree(freep);
} }
} else { // get a new number } else { // get a new number
if (hp == NULL) { if (hp == NULL) {
@ -398,11 +398,11 @@ void mf_put(memfile_T *mfp, bhdr_T *hp, bool dirty, bool infile)
/// Signal block as no longer used (may put it in the free list). /// Signal block as no longer used (may put it in the free list).
void mf_free(memfile_T *mfp, bhdr_T *hp) void mf_free(memfile_T *mfp, bhdr_T *hp)
{ {
free(hp->bh_data); // free data xfree(hp->bh_data); // free data
mf_rem_hash(mfp, hp); // get *hp out of the hash list mf_rem_hash(mfp, hp); // get *hp out of the hash list
mf_rem_used(mfp, hp); // get *hp out of the used list mf_rem_used(mfp, hp); // get *hp out of the used list
if (hp->bh_bnum < 0) { if (hp->bh_bnum < 0) {
free(hp); // don't want negative numbers in free list xfree(hp); // don't want negative numbers in free list
mfp->mf_neg_count--; mfp->mf_neg_count--;
} else { } else {
mf_ins_free(mfp, hp); // put *hp in the free list mf_ins_free(mfp, hp); // put *hp in the free list
@ -627,7 +627,7 @@ static bhdr_T *mf_release(memfile_T *mfp, unsigned page_count)
/// Make sure page_count of bh_data is right. /// Make sure page_count of bh_data is right.
if (hp->bh_page_count != page_count) { if (hp->bh_page_count != page_count) {
free(hp->bh_data); xfree(hp->bh_data);
hp->bh_data = xmalloc(mfp->mf_page_size * page_count); hp->bh_data = xmalloc(mfp->mf_page_size * page_count);
hp->bh_page_count = page_count; hp->bh_page_count = page_count;
} }
@ -682,8 +682,8 @@ static bhdr_T *mf_alloc_bhdr(memfile_T *mfp, unsigned page_count)
/// Free a block header and its block memory. /// Free a block header and its block memory.
static void mf_free_bhdr(bhdr_T *hp) static void mf_free_bhdr(bhdr_T *hp)
{ {
free(hp->bh_data); xfree(hp->bh_data);
free(hp); xfree(hp);
} }
/// Insert a block in the free list. /// Insert a block in the free list.
@ -843,7 +843,7 @@ static int mf_trans_add(memfile_T *mfp, bhdr_T *hp)
freep->bh_page_count -= page_count; freep->bh_page_count -= page_count;
} else { } else {
freep = mf_rem_free(mfp); freep = mf_rem_free(mfp);
free(freep); xfree(freep);
} }
} else { } else {
new_bnum = mfp->mf_blocknr_max; new_bnum = mfp->mf_blocknr_max;
@ -881,7 +881,7 @@ blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr)
// remove entry from the trans list // remove entry from the trans list
mf_hash_rem_item(&mfp->mf_trans, (mf_hashitem_T *)np); mf_hash_rem_item(&mfp->mf_trans, (mf_hashitem_T *)np);
free(np); xfree(np);
return new_bnum; return new_bnum;
} }
@ -902,7 +902,7 @@ void mf_set_ffname(memfile_T *mfp)
void mf_fullname(memfile_T *mfp) void mf_fullname(memfile_T *mfp)
{ {
if (mfp != NULL && mfp->mf_fname != NULL && mfp->mf_ffname != NULL) { if (mfp != NULL && mfp->mf_fname != NULL && mfp->mf_ffname != NULL) {
free(mfp->mf_fname); xfree(mfp->mf_fname);
mfp->mf_fname = mfp->mf_ffname; mfp->mf_fname = mfp->mf_ffname;
mfp->mf_ffname = NULL; mfp->mf_ffname = NULL;
} }
@ -940,8 +940,8 @@ static void mf_do_open(memfile_T *mfp, char_u *fname, int flags)
// If the file cannot be opened, use memory only // If the file cannot be opened, use memory only
if (mfp->mf_fd < 0) { if (mfp->mf_fd < 0) {
free(mfp->mf_fname); xfree(mfp->mf_fname);
free(mfp->mf_ffname); xfree(mfp->mf_ffname);
mfp->mf_fname = NULL; mfp->mf_fname = NULL;
mfp->mf_ffname = NULL; mfp->mf_ffname = NULL;
} else { } else {
@ -979,7 +979,7 @@ static void mf_hash_init(mf_hashtab_T *mht)
static void mf_hash_free(mf_hashtab_T *mht) static void mf_hash_free(mf_hashtab_T *mht)
{ {
if (mht->mht_buckets != mht->mht_small_buckets) if (mht->mht_buckets != mht->mht_small_buckets)
free(mht->mht_buckets); xfree(mht->mht_buckets);
} }
/// Free the array of a hash table and all the items it contains. /// Free the array of a hash table and all the items it contains.
@ -990,7 +990,7 @@ static void mf_hash_free_all(mf_hashtab_T *mht)
for (size_t idx = 0; idx <= mht->mht_mask; idx++) for (size_t idx = 0; idx <= mht->mht_mask; idx++)
for (mf_hashitem_T *mhi = mht->mht_buckets[idx]; mhi != NULL; mhi = next) { for (mf_hashitem_T *mhi = mht->mht_buckets[idx]; mhi != NULL; mhi = next) {
next = mhi->mhi_next; next = mhi->mhi_next;
free(mhi); xfree(mhi);
} }
mf_hash_free(mht); mf_hash_free(mht);
@ -1088,7 +1088,7 @@ static void mf_hash_grow(mf_hashtab_T *mht)
} }
if (mht->mht_buckets != mht->mht_small_buckets) if (mht->mht_buckets != mht->mht_small_buckets)
free(mht->mht_buckets); xfree(mht->mht_buckets);
mht->mht_buckets = buckets; mht->mht_buckets = buckets;
mht->mht_mask = (mht->mht_mask + 1) * MHT_GROWTH_FACTOR - 1; mht->mht_mask = (mht->mht_mask + 1) * MHT_GROWTH_FACTOR - 1;

View File

@ -373,7 +373,7 @@ error:
if (mfp != NULL) { if (mfp != NULL) {
if (hp) if (hp)
mf_put(mfp, hp, false, false); mf_put(mfp, hp, false, false);
mf_close(mfp, true); /* will also free(mfp->mf_fname) */ mf_close(mfp, true); /* will also xfree(mfp->mf_fname) */
} }
buf->b_ml.ml_mfp = NULL; buf->b_ml.ml_mfp = NULL;
return FAIL; return FAIL;
@ -418,7 +418,7 @@ void ml_setname(buf_T *buf)
/* if the file name is the same we don't have to do anything */ /* if the file name is the same we don't have to do anything */
if (fnamecmp(fname, mfp->mf_fname) == 0) { if (fnamecmp(fname, mfp->mf_fname) == 0) {
free(fname); xfree(fname);
success = TRUE; success = TRUE;
break; break;
} }
@ -431,14 +431,14 @@ void ml_setname(buf_T *buf)
/* try to rename the swap file */ /* try to rename the swap file */
if (vim_rename(mfp->mf_fname, fname) == 0) { if (vim_rename(mfp->mf_fname, fname) == 0) {
success = TRUE; success = TRUE;
free(mfp->mf_fname); xfree(mfp->mf_fname);
mfp->mf_fname = fname; mfp->mf_fname = fname;
free(mfp->mf_ffname); xfree(mfp->mf_ffname);
mf_set_ffname(mfp); mf_set_ffname(mfp);
ml_upd_block0(buf, UB_SAME_DIR); ml_upd_block0(buf, UB_SAME_DIR);
break; break;
} }
free(fname); /* this fname didn't work, try another */ xfree(fname); /* this fname didn't work, try another */
} }
if (mfp->mf_fd == -1) { /* need to (re)open the swap file */ if (mfp->mf_fd == -1) { /* need to (re)open the swap file */
@ -567,9 +567,9 @@ void ml_close(buf_T *buf, int del_file)
return; return;
mf_close(buf->b_ml.ml_mfp, del_file); /* close the .swp file */ mf_close(buf->b_ml.ml_mfp, del_file); /* close the .swp file */
if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY)) if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY))
free(buf->b_ml.ml_line_ptr); xfree(buf->b_ml.ml_line_ptr);
free(buf->b_ml.ml_stack); xfree(buf->b_ml.ml_stack);
free(buf->b_ml.ml_chunksize); xfree(buf->b_ml.ml_chunksize);
buf->b_ml.ml_chunksize = NULL; buf->b_ml.ml_chunksize = NULL;
buf->b_ml.ml_mfp = NULL; buf->b_ml.ml_mfp = NULL;
@ -935,7 +935,7 @@ void ml_recover(void)
/* need to reallocate the memory used to store the data */ /* need to reallocate the memory used to store the data */
p = xmalloc(mfp->mf_page_size); p = xmalloc(mfp->mf_page_size);
memmove(p, hp->bh_data, previous_page_size); memmove(p, hp->bh_data, previous_page_size);
free(hp->bh_data); xfree(hp->bh_data);
hp->bh_data = p; hp->bh_data = p;
b0p = hp->bh_data; b0p = hp->bh_data;
} }
@ -1008,7 +1008,7 @@ void ml_recover(void)
set_fileformat(b0_ff - 1, OPT_LOCAL); set_fileformat(b0_ff - 1, OPT_LOCAL);
if (b0_fenc != NULL) { if (b0_fenc != NULL) {
set_option_value((char_u *)"fenc", 0L, b0_fenc, OPT_LOCAL); set_option_value((char_u *)"fenc", 0L, b0_fenc, OPT_LOCAL);
free(b0_fenc); xfree(b0_fenc);
} }
unchanged(curbuf, TRUE); unchanged(curbuf, TRUE);
@ -1194,7 +1194,7 @@ void ml_recover(void)
/* Need to copy one line, fetching the other one may flush it. */ /* Need to copy one line, fetching the other one may flush it. */
p = vim_strsave(ml_get(idx)); p = vim_strsave(ml_get(idx));
i = STRCMP(p, ml_get(idx + lnum)); i = STRCMP(p, ml_get(idx + lnum));
free(p); xfree(p);
if (i != 0) { if (i != 0) {
changed_int(); changed_int();
++curbuf->b_changedtick; ++curbuf->b_changedtick;
@ -1237,16 +1237,16 @@ void ml_recover(void)
redraw_curbuf_later(NOT_VALID); redraw_curbuf_later(NOT_VALID);
theend: theend:
free(fname_used); xfree(fname_used);
recoverymode = FALSE; recoverymode = FALSE;
if (mfp != NULL) { if (mfp != NULL) {
if (hp != NULL) if (hp != NULL)
mf_put(mfp, hp, false, false); mf_put(mfp, hp, false, false);
mf_close(mfp, false); /* will also free(mfp->mf_fname) */ mf_close(mfp, false); /* will also xfree(mfp->mf_fname) */
} }
if (buf != NULL) { //may be NULL if swap file not found. if (buf != NULL) { //may be NULL if swap file not found.
free(buf->b_ml.ml_stack); xfree(buf->b_ml.ml_stack);
free(buf); xfree(buf);
} }
if (serious_error && called_from_main) if (serious_error && called_from_main)
ml_close(curbuf, TRUE); ml_close(curbuf, TRUE);
@ -1348,7 +1348,7 @@ recover_names (
tail = concat_fnames(dir_name, tail, TRUE); tail = concat_fnames(dir_name, tail, TRUE);
} }
num_names = recov_file_names(names, tail, FALSE); num_names = recov_file_names(names, tail, FALSE);
free(tail); xfree(tail);
} }
} }
@ -1372,7 +1372,7 @@ recover_names (
swapname = NULL; swapname = NULL;
num_files = 1; num_files = 1;
} }
free(swapname); xfree(swapname);
} }
} }
@ -1386,9 +1386,9 @@ recover_names (
/* Remove the name from files[i]. Move further entries /* Remove the name from files[i]. Move further entries
* down. When the array becomes empty free it here, since * down. When the array becomes empty free it here, since
* FreeWild() won't be called below. */ * FreeWild() won't be called below. */
free(files[i]); xfree(files[i]);
if (--num_files == 0) if (--num_files == 0)
free(files); xfree(files);
else else
for (; i < num_files; ++i) for (; i < num_files; ++i)
files[i] = files[i + 1]; files[i] = files[i + 1];
@ -1429,11 +1429,11 @@ recover_names (
file_count += num_files; file_count += num_files;
for (int i = 0; i < num_names; ++i) for (int i = 0; i < num_names; ++i)
free(names[i]); xfree(names[i]);
if (num_files > 0) if (num_files > 0)
FreeWild(num_files, files); FreeWild(num_files, files);
} }
free(dir_name); xfree(dir_name);
return file_count; return file_count;
} }
@ -1453,8 +1453,8 @@ static char_u *make_percent_swname(char_u *dir, char_u *name)
if (vim_ispathsep(*d)) if (vim_ispathsep(*d))
*d = '%'; *d = '%';
d = concat_fnames(dir, s, TRUE); d = concat_fnames(dir, s, TRUE);
free(s); xfree(s);
free(f); xfree(f);
} }
return d; return d;
} }
@ -1582,7 +1582,7 @@ static int recov_file_names(char_u **names, char_u *path, int prepend_dot)
if (STRCMP(p, names[num_names]) != 0) if (STRCMP(p, names[num_names]) != 0)
++num_names; ++num_names;
else else
free(names[num_names]); xfree(names[num_names]);
} else } else
++num_names; ++num_names;
@ -2339,7 +2339,7 @@ int ml_replace(linenr_T lnum, char_u *line, int copy)
if (curbuf->b_ml.ml_line_lnum != lnum) /* other line buffered */ if (curbuf->b_ml.ml_line_lnum != lnum) /* other line buffered */
ml_flush_line(curbuf); /* flush it */ ml_flush_line(curbuf); /* flush it */
else if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY) /* same line allocated */ else if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY) /* same line allocated */
free(curbuf->b_ml.ml_line_ptr); /* free it */ xfree(curbuf->b_ml.ml_line_ptr); /* free it */
curbuf->b_ml.ml_line_ptr = line; curbuf->b_ml.ml_line_ptr = line;
curbuf->b_ml.ml_line_lnum = lnum; curbuf->b_ml.ml_line_lnum = lnum;
curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY; curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY;
@ -2694,7 +2694,7 @@ static void ml_flush_line(buf_T *buf)
(void)ml_delete_int(buf, lnum, FALSE); (void)ml_delete_int(buf, lnum, FALSE);
} }
} }
free(new_line); xfree(new_line);
entered = FALSE; entered = FALSE;
} }
@ -2938,7 +2938,7 @@ static int ml_add_stack(buf_T *buf)
infoptr_T *newstack = xmalloc(sizeof(infoptr_T) * infoptr_T *newstack = xmalloc(sizeof(infoptr_T) *
(buf->b_ml.ml_stack_size + STACK_INCR)); (buf->b_ml.ml_stack_size + STACK_INCR));
memmove(newstack, buf->b_ml.ml_stack, (size_t)top * sizeof(infoptr_T)); memmove(newstack, buf->b_ml.ml_stack, (size_t)top * sizeof(infoptr_T));
free(buf->b_ml.ml_stack); xfree(buf->b_ml.ml_stack);
buf->b_ml.ml_stack = newstack; buf->b_ml.ml_stack = newstack;
buf->b_ml.ml_stack_size += STACK_INCR; buf->b_ml.ml_stack_size += STACK_INCR;
} }
@ -3070,7 +3070,7 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name
r = NULL; r = NULL;
if ((s = make_percent_swname(dir_name, fname)) != NULL) { if ((s = make_percent_swname(dir_name, fname)) != NULL) {
r = modname(s, (char_u *)".swp", FALSE); r = modname(s, (char_u *)".swp", FALSE);
free(s); xfree(s);
} }
return r; return r;
} }
@ -3089,7 +3089,7 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name
return NULL; return NULL;
s = get_file_in_dir(r, dir_name); s = get_file_in_dir(r, dir_name);
free(r); xfree(r);
return s; return s;
} }
@ -3129,7 +3129,7 @@ get_file_in_dir (
t = concat_fnames(fname, dname + 2, TRUE); t = concat_fnames(fname, dname + 2, TRUE);
*tail = save_char; *tail = save_char;
retval = concat_fnames(t, tail, TRUE); retval = concat_fnames(t, tail, TRUE);
free(t); xfree(t);
} }
} else { } else {
retval = concat_fnames(dname, tail, TRUE); retval = concat_fnames(dname, tail, TRUE);
@ -3264,7 +3264,7 @@ findswapname (
if (fname == NULL) /* must be out of memory */ if (fname == NULL) /* must be out of memory */
break; break;
if ((n = (int)STRLEN(fname)) == 0) { /* safety check */ if ((n = (int)STRLEN(fname)) == 0) { /* safety check */
free(fname); xfree(fname);
fname = NULL; fname = NULL;
break; break;
} }
@ -3394,7 +3394,7 @@ findswapname (
if (process_still_running && choice >= 4) if (process_still_running && choice >= 4)
choice++; /* Skip missing "Delete it" button */ choice++; /* Skip missing "Delete it" button */
# endif # endif
free(name); xfree(name);
/* pretend screen didn't scroll, need redraw anyway */ /* pretend screen didn't scroll, need redraw anyway */
msg_scrolled = 0; msg_scrolled = 0;
@ -3447,7 +3447,7 @@ findswapname (
if (fname[n - 1] == 'a') { /* ".s?a" */ if (fname[n - 1] == 'a') { /* ".s?a" */
if (fname[n - 2] == 'a') { /* ".saa": tried enough, give up */ if (fname[n - 2] == 'a') { /* ".saa": tried enough, give up */
EMSG(_("E326: Too many swap files found")); EMSG(_("E326: Too many swap files found"));
free(fname); xfree(fname);
fname = NULL; fname = NULL;
break; break;
} }
@ -3457,7 +3457,7 @@ findswapname (
--fname[n - 1]; /* ".swo", ".swn", etc. */ --fname[n - 1]; /* ".swo", ".swn", etc. */
} }
free(dir_name); xfree(dir_name);
return fname; return fname;
} }

View File

@ -18,6 +18,14 @@
# include "memory.c.generated.h" # include "memory.c.generated.h"
#endif #endif
#if defined(USE_JEMALLOC) && !defined(UNIT_TESTING)
#include "jemalloc/jemalloc.h"
#define malloc(size) je_malloc(size)
#define calloc(count, size) je_calloc(count, size)
#define realloc(ptr, size) je_realloc(ptr, size)
#define free(ptr) je_free(ptr)
#endif
/// Try to free memory. Used when trying to recover from out of memory errors. /// Try to free memory. Used when trying to recover from out of memory errors.
/// @see {xmalloc} /// @see {xmalloc}
static void try_to_free_memory(void) static void try_to_free_memory(void)
@ -92,6 +100,12 @@ void *xmalloc(size_t size)
return ret; return ret;
} }
/// free wrapper that returns delegates to the backing memory manager
void xfree(void *ptr)
{
free(ptr);
}
/// calloc() wrapper /// calloc() wrapper
/// ///
/// @see {xmalloc} /// @see {xmalloc}
@ -362,19 +376,7 @@ size_t xstrlcpy(char *restrict dst, const char *restrict src, size_t size)
char *xstrdup(const char *str) char *xstrdup(const char *str)
FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET
{ {
char *ret = strdup(str); return xmemdupz(str, strlen(str));
if (!ret) {
try_to_free_memory();
ret = strdup(str);
if (!ret) {
mch_errmsg(e_outofmem);
mch_errmsg("\n");
preserve_exit();
}
}
return ret;
} }
/// A version of memchr that starts the search at `src + len`. /// A version of memchr that starts the search at `src + len`.
@ -541,8 +543,8 @@ void free_all_mem(void)
clear_sb_text(); /* free any scrollback text */ clear_sb_text(); /* free any scrollback text */
/* Free some global vars. */ /* Free some global vars. */
free(last_cmdline); xfree(last_cmdline);
free(new_last_cmdline); xfree(new_last_cmdline);
set_keep_msg(NULL, 0); set_keep_msg(NULL, 0);
/* Clear cmdline history. */ /* Clear cmdline history. */

View File

@ -188,7 +188,7 @@ ex_menu (
if (modes & (1 << i)) { if (modes & (1 << i)) {
p = popup_mode_name(menu_path, i); p = popup_mode_name(menu_path, i);
menu_nable_recurse(root_menu, p, MENU_ALL_MODES, enable); menu_nable_recurse(root_menu, p, MENU_ALL_MODES, enable);
free(p); xfree(p);
} }
} }
menu_nable_recurse(root_menu, menu_path, modes, enable); menu_nable_recurse(root_menu, menu_path, modes, enable);
@ -207,7 +207,7 @@ ex_menu (
if (modes & (1 << i)) { if (modes & (1 << i)) {
p = popup_mode_name(menu_path, i); p = popup_mode_name(menu_path, i);
remove_menu(&root_menu, p, MENU_ALL_MODES, TRUE); remove_menu(&root_menu, p, MENU_ALL_MODES, TRUE);
free(p); xfree(p);
} }
} }
@ -241,11 +241,11 @@ ex_menu (
// Include all modes, to make ":amenu" work // Include all modes, to make ":amenu" work
menuarg.modes = modes; menuarg.modes = modes;
add_menu_path(p, &menuarg, pri_tab, map_to); add_menu_path(p, &menuarg, pri_tab, map_to);
free(p); xfree(p);
} }
} }
free(map_buf); xfree(map_buf);
} }
@ -391,12 +391,12 @@ add_menu_path (
menup = &menu->children; menup = &menu->children;
parent = menu; parent = menu;
name = next_name; name = next_name;
free(dname); xfree(dname);
dname = NULL; dname = NULL;
if (pri_tab[pri_idx + 1] != -1) if (pri_tab[pri_idx + 1] != -1)
++pri_idx; ++pri_idx;
} }
free(path_name); xfree(path_name);
/* /*
* Only add system menu items which have not been defined yet. * Only add system menu items which have not been defined yet.
@ -470,8 +470,8 @@ add_menu_path (
return OK; return OK;
erret: erret:
free(path_name); xfree(path_name);
free(dname); xfree(dname);
/* Delete any empty submenu we added before discovering the error. Repeat /* Delete any empty submenu we added before discovering the error. Repeat
* for higher levels. */ * for higher levels. */
@ -663,14 +663,14 @@ static void free_menu(vimmenu_T **menup)
/* Don't change *menup until after calling gui_mch_destroy_menu(). The /* Don't change *menup until after calling gui_mch_destroy_menu(). The
* MacOS code needs the original structure to properly delete the menu. */ * MacOS code needs the original structure to properly delete the menu. */
*menup = menu->next; *menup = menu->next;
free(menu->name); xfree(menu->name);
free(menu->dname); xfree(menu->dname);
free(menu->en_name); xfree(menu->en_name);
free(menu->en_dname); xfree(menu->en_dname);
free(menu->actext); xfree(menu->actext);
for (i = 0; i < MENU_MODES; i++) for (i = 0; i < MENU_MODES; i++)
free_menu_string(menu, i); free_menu_string(menu, i);
free(menu); xfree(menu);
} }
@ -686,7 +686,7 @@ static void free_menu_string(vimmenu_T *menu, int idx)
if (menu->strings[i] == menu->strings[idx]) if (menu->strings[i] == menu->strings[idx])
count++; count++;
if (count == 1) if (count == 1)
free(menu->strings[idx]); xfree(menu->strings[idx]);
menu->strings[idx] = NULL; menu->strings[idx] = NULL;
} }
@ -711,11 +711,11 @@ static int show_menus(char_u *path_name, int modes)
/* Found menu */ /* Found menu */
if (*p != NUL && menu->children == NULL) { if (*p != NUL && menu->children == NULL) {
EMSG(_(e_notsubmenu)); EMSG(_(e_notsubmenu));
free(path_name); xfree(path_name);
return FAIL; return FAIL;
} else if ((menu->modes & modes) == 0x0) { } else if ((menu->modes & modes) == 0x0) {
EMSG(_(e_othermode)); EMSG(_(e_othermode));
free(path_name); xfree(path_name);
return FAIL; return FAIL;
} }
break; break;
@ -724,14 +724,14 @@ static int show_menus(char_u *path_name, int modes)
} }
if (menu == NULL) { if (menu == NULL) {
EMSG2(_(e_nomenu), name); EMSG2(_(e_nomenu), name);
free(path_name); xfree(path_name);
return FAIL; return FAIL;
} }
name = p; name = p;
parent = menu; parent = menu;
menu = menu->children; menu = menu->children;
} }
free(path_name); xfree(path_name);
/* Now we have found the matching menu, and we list the mappings */ /* Now we have found the matching menu, and we list the mappings */
/* Highlight title */ /* Highlight title */
@ -893,7 +893,7 @@ char_u *set_context_in_menu_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forc
* Menu path continues, but we have reached a leaf. * Menu path continues, but we have reached a leaf.
* Or menu exists only in another mode. * Or menu exists only in another mode.
*/ */
free(path_name); xfree(path_name);
return NULL; return NULL;
} }
break; break;
@ -902,13 +902,13 @@ char_u *set_context_in_menu_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forc
} }
if (menu == NULL) { if (menu == NULL) {
/* No menu found with the name we were looking for */ /* No menu found with the name we were looking for */
free(path_name); xfree(path_name);
return NULL; return NULL;
} }
name = p; name = p;
menu = menu->children; menu = menu->children;
} }
free(path_name); xfree(path_name);
xp->xp_context = expand_menus ? EXPAND_MENUNAMES : EXPAND_MENUS; xp->xp_context = expand_menus ? EXPAND_MENUNAMES : EXPAND_MENUS;
xp->xp_pattern = after_dot; xp->xp_pattern = after_dot;
@ -1289,7 +1289,7 @@ void ex_emenu(exarg_T *eap)
menu = menu->children; menu = menu->children;
name = p; name = p;
} }
free(saved_name); xfree(saved_name);
if (menu == NULL) { if (menu == NULL) {
EMSG2(_("E334: Menu not found: %s"), eap->arg); EMSG2(_("E334: Menu not found: %s"), eap->arg);
return; return;
@ -1410,7 +1410,7 @@ vimmenu_T *gui_find_menu(char_u *path_name)
if (menu == NULL) if (menu == NULL)
EMSG(_("E337: Menu not found - check menu names")); EMSG(_("E337: Menu not found - check menu names"));
theend: theend:
free(saved_name); xfree(saved_name);
return menu; return menu;
} }
#endif #endif
@ -1429,9 +1429,9 @@ static garray_T menutrans_ga = GA_EMPTY_INIT_VALUE;
#define FREE_MENUTRANS(mt) \ #define FREE_MENUTRANS(mt) \
menutrans_T* _mt = (mt); \ menutrans_T* _mt = (mt); \
free(_mt->from); \ xfree(_mt->from); \
free(_mt->from_noamp); \ xfree(_mt->from_noamp); \
free(_mt->to) xfree(_mt->to)
/* /*
* ":menutrans". * ":menutrans".
@ -1514,11 +1514,11 @@ static char_u *menutrans_lookup(char_u *name, int len)
name[len] = c; name[len] = c;
for (int i = 0; i < menutrans_ga.ga_len; i++) { for (int i = 0; i < menutrans_ga.ga_len; i++) {
if (STRCMP(dname, tp[i].from_noamp) == 0) { if (STRCMP(dname, tp[i].from_noamp) == 0) {
free(dname); xfree(dname);
return tp[i].to; return tp[i].to;
} }
} }
free(dname); xfree(dname);
return NULL; return NULL;
} }

View File

@ -200,7 +200,7 @@ msg_attr_keep (
* Columns + sc_col) * Columns + sc_col)
set_keep_msg(s, 0); set_keep_msg(s, 0);
free(buf); xfree(buf);
--entered; --entered;
return retval; return retval;
} }
@ -362,7 +362,7 @@ static char_u *last_sourcing_name = NULL;
*/ */
void reset_last_sourcing(void) void reset_last_sourcing(void)
{ {
free(last_sourcing_name); xfree(last_sourcing_name);
last_sourcing_name = NULL; last_sourcing_name = NULL;
last_sourcing_lnum = 0; last_sourcing_lnum = 0;
} }
@ -433,18 +433,18 @@ void msg_source(int attr)
p = get_emsg_source(); p = get_emsg_source();
if (p != NULL) { if (p != NULL) {
msg_attr(p, attr); msg_attr(p, attr);
free(p); xfree(p);
} }
p = get_emsg_lnum(); p = get_emsg_lnum();
if (p != NULL) { if (p != NULL) {
msg_attr(p, hl_attr(HLF_N)); msg_attr(p, hl_attr(HLF_N));
free(p); xfree(p);
last_sourcing_lnum = sourcing_lnum; /* only once for each line */ last_sourcing_lnum = sourcing_lnum; /* only once for each line */
} }
/* remember the last sourcing name printed, also when it's empty */ /* remember the last sourcing name printed, also when it's empty */
if (sourcing_name == NULL || other_sourcing_name()) { if (sourcing_name == NULL || other_sourcing_name()) {
free(last_sourcing_name); xfree(last_sourcing_name);
if (sourcing_name == NULL) if (sourcing_name == NULL)
last_sourcing_name = NULL; last_sourcing_name = NULL;
else else
@ -525,13 +525,13 @@ int emsg(char_u *s)
if (p != NULL) { if (p != NULL) {
STRCAT(p, "\n"); STRCAT(p, "\n");
redir_write(p, -1); redir_write(p, -1);
free(p); xfree(p);
} }
p = get_emsg_lnum(); p = get_emsg_lnum();
if (p != NULL) { if (p != NULL) {
STRCAT(p, "\n"); STRCAT(p, "\n");
redir_write(p, -1); redir_write(p, -1);
free(p); xfree(p);
} }
redir_write(s, -1); redir_write(s, -1);
return TRUE; return TRUE;
@ -726,8 +726,8 @@ int delete_first_msg(void)
assert(msg_hist_len == 1); assert(msg_hist_len == 1);
last_msg_hist = NULL; last_msg_hist = NULL;
} }
free(p->msg); xfree(p->msg);
free(p); xfree(p);
--msg_hist_len; --msg_hist_len;
return OK; return OK;
} }
@ -949,7 +949,7 @@ void wait_return(int redraw)
reset_last_sourcing(); reset_last_sourcing();
if (keep_msg != NULL && vim_strsize(keep_msg) >= if (keep_msg != NULL && vim_strsize(keep_msg) >=
(Rows - cmdline_row - 1) * Columns + sc_col) { (Rows - cmdline_row - 1) * Columns + sc_col) {
free(keep_msg); xfree(keep_msg);
keep_msg = NULL; /* don't redisplay message, it's too long */ keep_msg = NULL; /* don't redisplay message, it's too long */
} }
@ -985,7 +985,7 @@ static void hit_return_msg(void)
*/ */
void set_keep_msg(char_u *s, int attr) void set_keep_msg(char_u *s, int attr)
{ {
free(keep_msg); xfree(keep_msg);
if (s != NULL && msg_silent == 0) if (s != NULL && msg_silent == 0)
keep_msg = vim_strsave(s); keep_msg = vim_strsave(s);
else else
@ -1002,7 +1002,7 @@ void msg_start(void)
int did_return = FALSE; int did_return = FALSE;
if (!msg_silent) { if (!msg_silent) {
free(keep_msg); xfree(keep_msg);
keep_msg = NULL; /* don't display old message now */ keep_msg = NULL; /* don't display old message now */
} }
@ -1088,7 +1088,7 @@ static void msg_home_replace_attr(char_u *fname, int attr)
name = home_replace_save(NULL, fname); name = home_replace_save(NULL, fname);
msg_outtrans_attr(name, attr); msg_outtrans_attr(name, attr);
free(name); xfree(name);
} }
/* /*
@ -1808,7 +1808,7 @@ static void inc_msg_scrolled(void)
p = tofree; p = tofree;
} }
set_vim_var_string(VV_SCROLLSTART, p, -1); set_vim_var_string(VV_SCROLLSTART, p, -1);
free(tofree); xfree(tofree);
} }
++msg_scrolled; ++msg_scrolled;
} }
@ -1879,7 +1879,7 @@ void clear_sb_text(void)
while (last_msgchunk != NULL) { while (last_msgchunk != NULL) {
mp = last_msgchunk->sb_prev; mp = last_msgchunk->sb_prev;
free(last_msgchunk); xfree(last_msgchunk);
last_msgchunk = mp; last_msgchunk = mp;
} }
} }
@ -2586,7 +2586,7 @@ void give_warning(char_u *message, bool hl) FUNC_ATTR_NONNULL_ARG(1)
++no_wait_return; ++no_wait_return;
set_vim_var_string(VV_WARNINGMSG, message, -1); set_vim_var_string(VV_WARNINGMSG, message, -1);
free(keep_msg); xfree(keep_msg);
keep_msg = NULL; keep_msg = NULL;
if (hl) if (hl)
keep_msg_attr = hl_attr(HLF_W); keep_msg_attr = hl_attr(HLF_W);
@ -2715,7 +2715,7 @@ do_dialog (
break; break;
} }
free(hotkeys); xfree(hotkeys);
State = oldState; State = oldState;
setmouse(); setmouse();
@ -2816,7 +2816,7 @@ static char_u * console_dialog_alloc(const char_u *message,
// Now allocate space for the strings // Now allocate space for the strings
free(confirm_msg); xfree(confirm_msg);
confirm_msg = xmalloc(len); confirm_msg = xmalloc(len);
*confirm_msg = NUL; *confirm_msg = NUL;

View File

@ -929,16 +929,16 @@ open_line (
curwin->w_cursor.col = 0; curwin->w_cursor.col = 0;
curwin->w_cursor.coladd = 0; curwin->w_cursor.coladd = 0;
ins_bytes(p_extra); /* will call changed_bytes() */ ins_bytes(p_extra); /* will call changed_bytes() */
free(p_extra); xfree(p_extra);
next_line = NULL; next_line = NULL;
} }
retval = TRUE; /* success! */ retval = TRUE; /* success! */
theend: theend:
curbuf->b_p_pi = saved_pi; curbuf->b_p_pi = saved_pi;
free(saved_line); xfree(saved_line);
free(next_line); xfree(next_line);
free(allocated); xfree(allocated);
return retval; return retval;
} }
@ -2432,7 +2432,7 @@ int get_keystroke(void)
#endif #endif
break; break;
} }
free(buf); xfree(buf);
mapped_ctrl_c = save_mapped_ctrl_c; mapped_ctrl_c = save_mapped_ctrl_c;
return n; return n;
@ -2784,7 +2784,7 @@ get_cmd_output (
call_shell(command, kShellOptDoOut | kShellOptExpand | flags, NULL); call_shell(command, kShellOptDoOut | kShellOptExpand | flags, NULL);
--no_check_timestamps; --no_check_timestamps;
free(command); xfree(command);
/* /*
* read the names from the file into memory * read the names from the file into memory
@ -2806,7 +2806,7 @@ get_cmd_output (
os_remove((char *)tempname); os_remove((char *)tempname);
if (i != len) { if (i != len) {
EMSG2(_(e_notread), tempname); EMSG2(_(e_notread), tempname);
free(buffer); xfree(buffer);
buffer = NULL; buffer = NULL;
} else if (ret_len == NULL) { } else if (ret_len == NULL) {
/* Change NUL into SOH, otherwise the string is truncated. */ /* Change NUL into SOH, otherwise the string is truncated. */
@ -2820,7 +2820,7 @@ get_cmd_output (
} }
done: done:
free(tempname); xfree(tempname);
return buffer; return buffer;
} }
@ -2833,8 +2833,8 @@ void FreeWild(int count, char_u **files)
if (count <= 0 || files == NULL) if (count <= 0 || files == NULL)
return; return;
while (count--) while (count--)
free(files[count]); xfree(files[count]);
free(files); xfree(files);
} }
/* /*

View File

@ -329,10 +329,10 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
: STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\"" : STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\""
: p_sxq); : p_sxq);
retval = os_call_shell(ncmd, opts, extra_shell_arg); retval = os_call_shell(ncmd, opts, extra_shell_arg);
free(ncmd); xfree(ncmd);
if (ecmd != cmd) if (ecmd != cmd)
free(ecmd); xfree(ecmd);
} }
} }
@ -387,7 +387,7 @@ int vim_chdir(char_u *new_dir)
if (dir_name == NULL) if (dir_name == NULL)
return -1; return -1;
r = os_chdir((char *)dir_name); r = os_chdir((char *)dir_name);
free(dir_name); xfree(dir_name);
return r; return r;
} }
@ -453,7 +453,7 @@ char *read_string(FILE *fd, size_t cnt)
for (size_t i = 0; i < cnt; i++) { for (size_t i = 0; i < cnt; i++) {
int c = getc(fd); int c = getc(fd);
if (c == EOF) { if (c == EOF) {
free(str); xfree(str);
return NULL; return NULL;
} }
str[i] = (uint8_t)c; str[i] = (uint8_t)c;

View File

@ -5,8 +5,6 @@
#include <uv.h> #include <uv.h>
#include <msgpack.h> #include <msgpack.h>
#include "nvim/lib/klist.h"
#include "nvim/api/private/helpers.h" #include "nvim/api/private/helpers.h"
#include "nvim/api/vim.h" #include "nvim/api/vim.h"
#include "nvim/msgpack_rpc/channel.h" #include "nvim/msgpack_rpc/channel.h"
@ -69,10 +67,6 @@ typedef struct {
uint64_t request_id; uint64_t request_id;
} RequestEvent; } RequestEvent;
#define _noop(x)
KMEMPOOL_INIT(RequestEventPool, RequestEvent, _noop)
static kmempool_t(RequestEventPool) *request_event_pool = NULL;
static uint64_t next_id = 1; static uint64_t next_id = 1;
static PMap(uint64_t) *channels = NULL; static PMap(uint64_t) *channels = NULL;
static PMap(cstr_t) *event_strings = NULL; static PMap(cstr_t) *event_strings = NULL;
@ -85,7 +79,6 @@ static msgpack_sbuffer out_buffer;
/// Initializes the module /// Initializes the module
void channel_init(void) void channel_init(void)
{ {
request_event_pool = kmp_init(RequestEventPool);
channels = pmap_new(uint64_t)(); channels = pmap_new(uint64_t)();
event_strings = pmap_new(cstr_t)(); event_strings = pmap_new(cstr_t)();
msgpack_sbuffer_init(&out_buffer); msgpack_sbuffer_init(&out_buffer);
@ -455,7 +448,7 @@ static void handle_request(Channel *channel, msgpack_object *request)
Array args = ARRAY_DICT_INIT; Array args = ARRAY_DICT_INIT;
msgpack_rpc_to_array(request->via.array.ptr + 3, &args); msgpack_rpc_to_array(request->via.array.ptr + 3, &args);
bool defer = (!kv_size(channel->call_stack) && handler.defer); bool defer = (!kv_size(channel->call_stack) && handler.defer);
RequestEvent *event_data = kmp_alloc(RequestEventPool, request_event_pool); RequestEvent *event_data = xmalloc(sizeof(RequestEvent));
event_data->channel = channel; event_data->channel = channel;
event_data->handler = handler; event_data->handler = handler;
event_data->args = args; event_data->args = args;
@ -485,9 +478,9 @@ static void on_request_event(Event event)
result, result,
&out_buffer)); &out_buffer));
// All arguments were freed already, but we still need to free the array // All arguments were freed already, but we still need to free the array
free(args.items); xfree(args.items);
decref(channel); decref(channel);
kmp_free(RequestEventPool, request_event_pool, e); xfree(e);
} }
static bool channel_write(Channel *channel, WBuffer *buffer) static bool channel_write(Channel *channel, WBuffer *buffer)
@ -608,7 +601,7 @@ static void unsubscribe(Channel *channel, char *event)
// Since the string is no longer used by other channels, release it's memory // Since the string is no longer used by other channels, release it's memory
pmap_del(cstr_t)(event_strings, event_string); pmap_del(cstr_t)(event_strings, event_string);
free(event_string); xfree(event_string);
} }
/// Close the channel streams/job and free the channel resources. /// Close the channel streams/job and free the channel resources.
@ -662,13 +655,13 @@ static void free_channel(Channel *channel)
pmap_free(cstr_t)(channel->subscribed_events); pmap_free(cstr_t)(channel->subscribed_events);
kv_destroy(channel->call_stack); kv_destroy(channel->call_stack);
kv_destroy(channel->delayed_notifications); kv_destroy(channel->delayed_notifications);
free(channel); xfree(channel);
} }
static void close_cb(uv_handle_t *handle) static void close_cb(uv_handle_t *handle)
{ {
free(handle->data); xfree(handle->data);
free(handle); xfree(handle);
} }
static Channel *register_channel(void) static Channel *register_channel(void)
@ -745,7 +738,7 @@ static WBuffer *serialize_request(uint64_t channel_id,
WBuffer *rv = wstream_new_buffer(xmemdup(sbuffer->data, sbuffer->size), WBuffer *rv = wstream_new_buffer(xmemdup(sbuffer->data, sbuffer->size),
sbuffer->size, sbuffer->size,
refcount, refcount,
free); xfree);
msgpack_sbuffer_clear(sbuffer); msgpack_sbuffer_clear(sbuffer);
api_free_array(args); api_free_array(args);
return rv; return rv;
@ -764,7 +757,7 @@ static WBuffer *serialize_response(uint64_t channel_id,
WBuffer *rv = wstream_new_buffer(xmemdup(sbuffer->data, sbuffer->size), WBuffer *rv = wstream_new_buffer(xmemdup(sbuffer->data, sbuffer->size),
sbuffer->size, sbuffer->size,
1, // responses only go though 1 channel 1, // responses only go though 1 channel
free); xfree);
msgpack_sbuffer_clear(sbuffer); msgpack_sbuffer_clear(sbuffer);
api_free_object(arg); api_free_object(arg);
return rv; return rv;

View File

@ -48,9 +48,9 @@ void remote_ui_disconnect(uint64_t channel_id)
// destroy pending screen updates // destroy pending screen updates
api_free_array(data->buffer); api_free_array(data->buffer);
pmap_del(uint64_t)(connected_uis, channel_id); pmap_del(uint64_t)(connected_uis, channel_id);
free(ui->data); xfree(ui->data);
ui_detach(ui); ui_detach(ui);
free(ui); xfree(ui);
} }
static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id,

View File

@ -57,7 +57,7 @@ bool server_init(void)
if (!os_getenv(LISTEN_ADDRESS_ENV_VAR)) { if (!os_getenv(LISTEN_ADDRESS_ENV_VAR)) {
char *listen_address = (char *)vim_tempname(); char *listen_address = (char *)vim_tempname();
os_setenv(LISTEN_ADDRESS_ENV_VAR, listen_address, 1); os_setenv(LISTEN_ADDRESS_ENV_VAR, listen_address, 1);
free(listen_address); xfree(listen_address);
} }
return server_start((char *)os_getenv(LISTEN_ADDRESS_ENV_VAR)) == 0; return server_start((char *)os_getenv(LISTEN_ADDRESS_ENV_VAR)) == 0;
@ -256,10 +256,10 @@ static void connection_cb(uv_stream_t *server, int status)
static void free_client(uv_handle_t *handle) static void free_client(uv_handle_t *handle)
{ {
free(handle); xfree(handle);
} }
static void free_server(uv_handle_t *handle) static void free_server(uv_handle_t *handle)
{ {
free(handle->data); xfree(handle->data);
} }

View File

@ -980,7 +980,7 @@ getcount:
/* now reset it, otherwise it's put in the history again */ /* now reset it, otherwise it's put in the history again */
keep_msg = kmsg; keep_msg = kmsg;
msg_attr(kmsg, keep_msg_attr); msg_attr(kmsg, keep_msg_attr);
free(kmsg); xfree(kmsg);
} }
setcursor(); setcursor();
ui_flush(); ui_flush();
@ -1015,7 +1015,7 @@ normal_end:
clear_showcmd(); clear_showcmd();
checkpcmark(); /* check if we moved since setting pcmark */ checkpcmark(); /* check if we moved since setting pcmark */
free(ca.searchbuf); xfree(ca.searchbuf);
if (has_mbyte) if (has_mbyte)
mb_adjust_cursor(); mb_adjust_cursor();
@ -1160,7 +1160,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
else { else {
AppendToRedobuffLit(repeat_cmdline, -1); AppendToRedobuffLit(repeat_cmdline, -1);
AppendToRedobuff(NL_STR); AppendToRedobuff(NL_STR);
free(repeat_cmdline); xfree(repeat_cmdline);
repeat_cmdline = NULL; repeat_cmdline = NULL;
} }
} }
@ -3342,7 +3342,7 @@ find_decl (
reset_search_dir(); reset_search_dir();
} }
free(pat); xfree(pat);
p_ws = save_p_ws; p_ws = save_p_ws;
p_scs = save_p_scs; p_scs = save_p_scs;
@ -4261,7 +4261,7 @@ static void nv_ident(cmdarg_T *cap)
} }
if (n == 0) { if (n == 0) {
EMSG(_(e_noident)); /* found dashes only */ EMSG(_(e_noident)); /* found dashes only */
free(buf); xfree(buf);
return; return;
} }
@ -4312,11 +4312,11 @@ static void nv_ident(cmdarg_T *cap)
/* Escape the argument properly for a shell command */ /* Escape the argument properly for a shell command */
ptr = vim_strnsave(ptr, n); ptr = vim_strnsave(ptr, n);
p = vim_strsave_shellescape(ptr, true, true); p = vim_strsave_shellescape(ptr, true, true);
free(ptr); xfree(ptr);
newbuf = (char_u *)xrealloc(buf, STRLEN(buf) + STRLEN(p) + 1); newbuf = (char_u *)xrealloc(buf, STRLEN(buf) + STRLEN(p) + 1);
buf = newbuf; buf = newbuf;
STRCAT(buf, p); STRCAT(buf, p);
free(p); xfree(p);
} else { } else {
if (cmdchar == '*') if (cmdchar == '*')
aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\");
@ -4365,7 +4365,7 @@ static void nv_ident(cmdarg_T *cap)
} else } else
do_cmdline_cmd(buf); do_cmdline_cmd(buf);
free(buf); xfree(buf);
} }
/* /*
@ -4724,7 +4724,7 @@ static void nv_gotofile(cmdarg_T *cap)
check_cursor_lnum(); check_cursor_lnum();
beginline(BL_SOL | BL_FIX); beginline(BL_SOL | BL_FIX);
} }
free(ptr); xfree(ptr);
} else } else
clearop(cap->oap); clearop(cap->oap);
} }

View File

@ -668,7 +668,7 @@ int get_expr_register(void)
if (new_line == NULL) if (new_line == NULL)
return NUL; return NUL;
if (*new_line == NUL) /* use previous line */ if (*new_line == NUL) /* use previous line */
free(new_line); xfree(new_line);
else else
set_expr_line(new_line); set_expr_line(new_line);
return '='; return '=';
@ -680,7 +680,7 @@ int get_expr_register(void)
*/ */
void set_expr_line(char_u *new_line) void set_expr_line(char_u *new_line)
{ {
free(expr_line); xfree(expr_line);
expr_line = new_line; expr_line = new_line;
} }
@ -709,7 +709,7 @@ char_u *get_expr_line(void)
++nested; ++nested;
rv = eval_to_string(expr_copy, NULL, TRUE); rv = eval_to_string(expr_copy, NULL, TRUE);
--nested; --nested;
free(expr_copy); xfree(expr_copy);
return rv; return rv;
} }
@ -843,7 +843,7 @@ void put_register(int name, void *reg)
get_yank_register(name, YREG_PUT); get_yank_register(name, YREG_PUT);
free_yank_all(); free_yank_all();
*y_current = *(struct yankreg *)reg; *y_current = *(struct yankreg *)reg;
free(reg); xfree(reg);
set_clipboard(name); set_clipboard(name);
} }
@ -923,11 +923,11 @@ static int stuff_yank(int regname, char_u *p)
{ {
/* check for read-only register */ /* check for read-only register */
if (regname != 0 && !valid_yank_reg(regname, TRUE)) { if (regname != 0 && !valid_yank_reg(regname, TRUE)) {
free(p); xfree(p);
return FAIL; return FAIL;
} }
if (regname == '_') { /* black hole: don't do anything */ if (regname == '_') { /* black hole: don't do anything */
free(p); xfree(p);
return OK; return OK;
} }
get_yank_register(regname, YREG_YANK); get_yank_register(regname, YREG_YANK);
@ -937,8 +937,8 @@ static int stuff_yank(int regname, char_u *p)
STRCPY(lp, *pp); STRCPY(lp, *pp);
// TODO(philix): use xstpcpy() in stuff_yank() // TODO(philix): use xstpcpy() in stuff_yank()
STRCAT(lp, p); STRCAT(lp, p);
free(p); xfree(p);
free(*pp); xfree(*pp);
*pp = lp; *pp = lp;
} else { } else {
free_yank_all(); free_yank_all();
@ -992,7 +992,7 @@ do_execreg (
EMSG(_(e_nolastcmd)); EMSG(_(e_nolastcmd));
return FAIL; return FAIL;
} }
free(new_last_cmdline); /* don't keep the cmdline containing @: */ xfree(new_last_cmdline); /* don't keep the cmdline containing @: */
new_last_cmdline = NULL; new_last_cmdline = NULL;
/* Escape all control characters with a CTRL-V */ /* Escape all control characters with a CTRL-V */
p = vim_strsave_escaped_ext( p = vim_strsave_escaped_ext(
@ -1006,13 +1006,13 @@ do_execreg (
retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); retval = put_in_typebuf(p + 5, TRUE, TRUE, silent);
else else
retval = put_in_typebuf(p, TRUE, TRUE, silent); retval = put_in_typebuf(p, TRUE, TRUE, silent);
free(p); xfree(p);
} else if (regname == '=') { } else if (regname == '=') {
p = get_expr_line(); p = get_expr_line();
if (p == NULL) if (p == NULL)
return FAIL; return FAIL;
retval = put_in_typebuf(p, TRUE, colon, silent); retval = put_in_typebuf(p, TRUE, colon, silent);
free(p); xfree(p);
} else if (regname == '.') { /* use last inserted text */ } else if (regname == '.') { /* use last inserted text */
p = get_last_insert_save(); p = get_last_insert_save();
if (p == NULL) { if (p == NULL) {
@ -1020,7 +1020,7 @@ do_execreg (
return FAIL; return FAIL;
} }
retval = put_in_typebuf(p, FALSE, colon, silent); retval = put_in_typebuf(p, FALSE, colon, silent);
free(p); xfree(p);
} else { } else {
get_yank_register(regname, YREG_PASTE); get_yank_register(regname, YREG_PASTE);
if (y_current->y_array == NULL) if (y_current->y_array == NULL)
@ -1044,7 +1044,7 @@ do_execreg (
} }
escaped = vim_strsave_escape_csi(y_current->y_array[i]); escaped = vim_strsave_escape_csi(y_current->y_array[i]);
retval = ins_typebuf(escaped, remap, 0, TRUE, silent); retval = ins_typebuf(escaped, remap, 0, TRUE, silent);
free(escaped); xfree(escaped);
if (retval == FAIL) if (retval == FAIL)
return FAIL; return FAIL;
if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent)
@ -1110,7 +1110,7 @@ put_in_typebuf (
retval = ins_typebuf(p, esc ? REMAP_NONE : REMAP_YES, retval = ins_typebuf(p, esc ? REMAP_NONE : REMAP_YES,
0, TRUE, silent); 0, TRUE, silent);
if (esc) if (esc)
free(p); xfree(p);
} }
if (colon && retval == OK) if (colon && retval == OK)
retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent);
@ -1154,7 +1154,7 @@ insert_reg (
return FAIL; return FAIL;
stuffescaped(arg, literally); stuffescaped(arg, literally);
if (allocated) if (allocated)
free(arg); xfree(arg);
} else { /* name or number register */ } else { /* name or number register */
get_yank_register(regname, YREG_PASTE); get_yank_register(regname, YREG_PASTE);
if (y_current->y_array == NULL) if (y_current->y_array == NULL)
@ -1804,7 +1804,7 @@ int op_replace(oparg_T *oap, int c)
ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE);
appended_lines_mark(curwin->w_cursor.lnum, 1L); appended_lines_mark(curwin->w_cursor.lnum, 1L);
oap->end.lnum++; oap->end.lnum++;
free(after_p); xfree(after_p);
} }
} }
} else { } else {
@ -2186,7 +2186,7 @@ void op_insert(oparg_T *oap, long count1)
curwin->w_cursor.col = oap->start.col; curwin->w_cursor.col = oap->start.col;
check_cursor(); check_cursor();
free(ins_text); xfree(ins_text);
} }
} }
} }
@ -2299,7 +2299,7 @@ int op_change(oparg_T *oap)
} }
check_cursor(); check_cursor();
changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L);
free(ins_text); xfree(ins_text);
} }
} }
@ -2341,9 +2341,9 @@ static void free_yank(long n)
long i; long i;
for (i = n; --i >= 0; ) { for (i = n; --i >= 0; ) {
free(y_current->y_array[i]); xfree(y_current->y_array[i]);
} }
free(y_current->y_array); xfree(y_current->y_array);
y_current->y_array = NULL; y_current->y_array = NULL;
} }
} }
@ -2507,7 +2507,7 @@ int op_yank(oparg_T *oap, int deleting, int mess)
new_ptr = xmalloc(sizeof(char_u *) * (curr->y_size + y_current->y_size)); new_ptr = xmalloc(sizeof(char_u *) * (curr->y_size + y_current->y_size));
for (j = 0; j < curr->y_size; ++j) for (j = 0; j < curr->y_size; ++j)
new_ptr[j] = curr->y_array[j]; new_ptr[j] = curr->y_array[j];
free(curr->y_array); xfree(curr->y_array);
curr->y_array = new_ptr; curr->y_array = new_ptr;
if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */
@ -2520,8 +2520,8 @@ int op_yank(oparg_T *oap, int deleting, int mess)
+ STRLEN(y_current->y_array[0]) + 1); + STRLEN(y_current->y_array[0]) + 1);
STRCPY(pnew, curr->y_array[--j]); STRCPY(pnew, curr->y_array[--j]);
STRCAT(pnew, y_current->y_array[0]); STRCAT(pnew, y_current->y_array[0]);
free(curr->y_array[j]); xfree(curr->y_array[j]);
free(y_current->y_array[0]); xfree(y_current->y_array[0]);
curr->y_array[j++] = pnew; curr->y_array[j++] = pnew;
y_idx = 1; y_idx = 1;
} else } else
@ -2529,7 +2529,7 @@ int op_yank(oparg_T *oap, int deleting, int mess)
while (y_idx < y_current->y_size) while (y_idx < y_current->y_size)
curr->y_array[j++] = y_current->y_array[y_idx++]; curr->y_array[j++] = y_current->y_array[y_idx++];
curr->y_size = j; curr->y_size = j;
free(y_current->y_array); xfree(y_current->y_array);
y_current = curr; y_current = curr;
} }
if (curwin->w_p_rnu) { if (curwin->w_p_rnu) {
@ -2735,7 +2735,7 @@ do_put (
goto end; goto end;
ptr = vim_strsave(get_cursor_pos_ptr()); ptr = vim_strsave(get_cursor_pos_ptr());
ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE);
free(ptr); xfree(ptr);
ptr = vim_strnsave(get_cursor_line_ptr(), curwin->w_cursor.col); ptr = vim_strnsave(get_cursor_line_ptr(), curwin->w_cursor.col);
ml_replace(curwin->w_cursor.lnum, ptr, FALSE); ml_replace(curwin->w_cursor.lnum, ptr, FALSE);
@ -3049,7 +3049,7 @@ do_put (
STRCAT(newp, ptr); STRCAT(newp, ptr);
/* insert second line */ /* insert second line */
ml_append(lnum, newp, (colnr_T)0, FALSE); ml_append(lnum, newp, (colnr_T)0, FALSE);
free(newp); xfree(newp);
oldp = ml_get(lnum); oldp = ml_get(lnum);
newp = (char_u *) xmalloc((size_t)(col + yanklen + 1)); newp = (char_u *) xmalloc((size_t)(col + yanklen + 1));
@ -3154,9 +3154,9 @@ error:
end: end:
if (allocated) if (allocated)
free(insert_string); xfree(insert_string);
if (regname == '=') if (regname == '=')
free(y_array); xfree(y_array);
VIsual_active = FALSE; VIsual_active = FALSE;
@ -3618,9 +3618,9 @@ int do_join(long count,
curwin->w_set_curswant = TRUE; curwin->w_set_curswant = TRUE;
theend: theend:
free(spaces); xfree(spaces);
if (remove_comments) if (remove_comments)
free(comments); xfree(comments);
return ret; return ret;
} }
@ -3681,7 +3681,7 @@ static int same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, in
while (vim_iswhite(line1[idx1])) while (vim_iswhite(line1[idx1]))
++idx1; ++idx1;
} }
free(line1); xfree(line1);
return idx2 == leader2_len && idx1 == leader1_len; return idx2 == leader2_len && idx1 == leader1_len;
} }
@ -4479,7 +4479,7 @@ int do_addsub(int command, linenr_T Prenum1)
*ptr = NUL; *ptr = NUL;
STRCAT(buf1, buf2); STRCAT(buf1, buf2);
ins_str(buf1); /* insert the new number */ ins_str(buf1); /* insert the new number */
free(buf1); xfree(buf1);
} }
--curwin->w_cursor.col; --curwin->w_cursor.col;
curwin->w_set_curswant = TRUE; curwin->w_set_curswant = TRUE;
@ -4556,7 +4556,7 @@ int read_viminfo_register(vir_T *virp, int force)
if (do_it) { if (do_it) {
if (size == 0) { if (size == 0) {
free(array); xfree(array);
} else if (size < limit) { } else if (size < limit) {
y_current->y_array = xrealloc(array, size * sizeof(char_u *)); y_current->y_array = xrealloc(array, size * sizeof(char_u *));
} else { } else {
@ -5018,7 +5018,7 @@ static void str_to_reg(struct yankreg *y_ptr, int yank_type, const char_u *str,
ssize_t s_len = extra + line_len; ssize_t s_len = extra + line_len;
if (append) { if (append) {
free(pp[lnum]); xfree(pp[lnum]);
append = false; // only first line is appended append = false; // only first line is appended
} }
pp[lnum] = s; pp[lnum] = s;
@ -5430,7 +5430,7 @@ static bool get_clipboard(int name, struct yankreg** target, bool quiet)
// a known-to-be charwise yank might have a final linebreak // a known-to-be charwise yank might have a final linebreak
// but otherwise there is no line after the final newline // but otherwise there is no line after the final newline
if (reg->y_type != MCHAR) { if (reg->y_type != MCHAR) {
free(reg->y_array[reg->y_size-1]); xfree(reg->y_array[reg->y_size-1]);
reg->y_size--; reg->y_size--;
if (reg->y_type == MAUTO) { if (reg->y_type == MAUTO) {
reg->y_type = MLINE; reg->y_type = MLINE;
@ -5459,9 +5459,9 @@ static bool get_clipboard(int name, struct yankreg** target, bool quiet)
err: err:
if (reg->y_array) { if (reg->y_array) {
for (int i = 0; i < reg->y_size; i++) { for (int i = 0; i < reg->y_size; i++) {
free(reg->y_array[i]); xfree(reg->y_array[i]);
} }
free(reg->y_array); xfree(reg->y_array);
} }
reg->y_array = NULL; reg->y_array = NULL;
reg->y_size = 0; reg->y_size = 0;

View File

@ -1827,11 +1827,11 @@ void set_init_1(void)
ga.ga_len += len; ga.ga_len += len;
} }
if (mustfree) if (mustfree)
free(p); xfree(p);
} }
if (ga.ga_data != NULL) { if (ga.ga_data != NULL) {
set_string_default("bsk", ga.ga_data); set_string_default("bsk", ga.ga_data);
free(ga.ga_data); xfree(ga.ga_data);
} }
} }
@ -1885,10 +1885,10 @@ void set_init_1(void)
options[opt_idx].def_val[VI_DEFAULT] = buf; options[opt_idx].def_val[VI_DEFAULT] = buf;
options[opt_idx].flags |= P_DEF_ALLOCED; options[opt_idx].flags |= P_DEF_ALLOCED;
} else } else
free(buf); /* cannot happen */ xfree(buf); /* cannot happen */
} }
if (mustfree) if (mustfree)
free(cdpath); xfree(cdpath);
} }
} }
@ -1958,7 +1958,7 @@ void set_init_1(void)
* split P_DEF_ALLOCED in two. * split P_DEF_ALLOCED in two.
*/ */
if (options[opt_idx].flags & P_DEF_ALLOCED) if (options[opt_idx].flags & P_DEF_ALLOCED)
free(options[opt_idx].def_val[VI_DEFAULT]); xfree(options[opt_idx].def_val[VI_DEFAULT]);
options[opt_idx].def_val[VI_DEFAULT] = p; options[opt_idx].def_val[VI_DEFAULT] = p;
options[opt_idx].flags |= P_DEF_ALLOCED; options[opt_idx].flags |= P_DEF_ALLOCED;
} }
@ -1998,7 +1998,7 @@ void set_init_1(void)
* for practical purposes, thus use that. It's not an alias to * for practical purposes, thus use that. It's not an alias to
* still support conversion between gb18030 and utf-8. */ * still support conversion between gb18030 and utf-8. */
p_enc = vim_strsave((char_u *)"cp936"); p_enc = vim_strsave((char_u *)"cp936");
free(p); xfree(p);
} }
if (mb_init() == NULL) { if (mb_init() == NULL) {
opt_idx = findoption((char_u *)"encoding"); opt_idx = findoption((char_u *)"encoding");
@ -2028,7 +2028,7 @@ void set_init_1(void)
#endif #endif
} else { } else {
free(p_enc); xfree(p_enc);
// mb_init() failed; fallback to utf8 and try again. // mb_init() failed; fallback to utf8 and try again.
p_enc = save_enc; p_enc = save_enc;
mb_init(); mb_init();
@ -2136,7 +2136,7 @@ void set_string_default(const char *name, const char_u *val)
int opt_idx = findoption((char_u *)name); int opt_idx = findoption((char_u *)name);
if (opt_idx >= 0) { if (opt_idx >= 0) {
if (options[opt_idx].flags & P_DEF_ALLOCED) { if (options[opt_idx].flags & P_DEF_ALLOCED) {
free(options[opt_idx].def_val[VI_DEFAULT]); xfree(options[opt_idx].def_val[VI_DEFAULT]);
} }
options[opt_idx].def_val[VI_DEFAULT] = (char_u *) xstrdup((char *) val); options[opt_idx].def_val[VI_DEFAULT] = (char_u *) xstrdup((char *) val);
@ -2276,7 +2276,7 @@ void set_init_3(void)
options[idx_srr].def_val[VI_DEFAULT] = p_srr; options[idx_srr].def_val[VI_DEFAULT] = p_srr;
} }
} }
free(p); xfree(p);
} }
#endif #endif
@ -2782,7 +2782,7 @@ do_set (
(char_u *)"indent,eol,start"); (char_u *)"indent,eol,start");
break; break;
} }
free(oldval); xfree(oldval);
oldval = *(char_u **)varp; oldval = *(char_u **)varp;
} }
/* /*
@ -2879,7 +2879,7 @@ do_set (
|| (flags & P_COMMA)) { || (flags & P_COMMA)) {
s = option_expand(opt_idx, newval); s = option_expand(opt_idx, newval);
if (s != NULL) { if (s != NULL) {
free(newval); xfree(newval);
newlen = (unsigned)STRLEN(s) + 1; newlen = (unsigned)STRLEN(s) + 1;
if (adding || prepending || removing) if (adding || prepending || removing)
newlen += (unsigned)STRLEN(origval) + 1; newlen += (unsigned)STRLEN(origval) + 1;
@ -3373,13 +3373,13 @@ void check_buf_options(buf_T *buf)
void free_string_option(char_u *p) void free_string_option(char_u *p)
{ {
if (p != empty_option) if (p != empty_option)
free(p); xfree(p);
} }
void clear_string_option(char_u **pp) void clear_string_option(char_u **pp)
{ {
if (*pp != empty_option) if (*pp != empty_option)
free(*pp); xfree(*pp);
*pp = empty_option; *pp = empty_option;
} }
@ -3768,7 +3768,7 @@ did_set_string_option (
if (errmsg == NULL) { if (errmsg == NULL) {
/* canonize the value, so that STRCMP() can be used on it */ /* canonize the value, so that STRCMP() can be used on it */
p = enc_canonize(*varp); p = enc_canonize(*varp);
free(*varp); xfree(*varp);
*varp = p; *varp = p;
if (varp == &p_enc) { if (varp == &p_enc) {
errmsg = mb_init(); errmsg = mb_init();
@ -3795,7 +3795,7 @@ did_set_string_option (
} else if (varp == &p_penc) { } else if (varp == &p_penc) {
/* Canonize printencoding if VIM standard one */ /* Canonize printencoding if VIM standard one */
p = enc_canonize(p_penc); p = enc_canonize(p_penc);
free(p_penc); xfree(p_penc);
p_penc = p; p_penc = p;
} else if (varp == &curbuf->b_p_keymap) { } else if (varp == &curbuf->b_p_keymap) {
/* load or unload key mapping tables */ /* load or unload key mapping tables */
@ -4456,7 +4456,7 @@ skip:
return e_invarg; /* illegal trailing comma as in "set cc=80," */ return e_invarg; /* illegal trailing comma as in "set cc=80," */
} }
free(wp->w_p_cc_cols); xfree(wp->w_p_cc_cols);
if (count == 0) if (count == 0)
wp->w_p_cc_cols = NULL; wp->w_p_cc_cols = NULL;
else { else {
@ -4649,7 +4649,7 @@ static char_u *compile_cap_prog(synblock_T *synblock)
/* Prepend a ^ so that we only match at one column */ /* Prepend a ^ so that we only match at one column */
re = concat_str((char_u *)"^", synblock->b_p_spc); re = concat_str((char_u *)"^", synblock->b_p_spc);
synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC); synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
free(re); xfree(re);
if (synblock->b_cap_prog == NULL) { if (synblock->b_cap_prog == NULL) {
synblock->b_cap_prog = rp; /* restore the previous program */ synblock->b_cap_prog = rp; /* restore the previous program */
return e_invarg; return e_invarg;
@ -5930,7 +5930,7 @@ showoptions (
os_breakcheck(); os_breakcheck();
} }
} }
free(items); xfree(items);
} }
/* /*
@ -6157,10 +6157,10 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int e
buf = xmalloc(MAXPATHL); buf = xmalloc(MAXPATHL);
home_replace(NULL, *valuep, buf, MAXPATHL, FALSE); home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
if (put_escstr(fd, buf, 2) == FAIL) { if (put_escstr(fd, buf, 2) == FAIL) {
free(buf); xfree(buf);
return FAIL; return FAIL;
} }
free(buf); xfree(buf);
} else if (put_escstr(fd, *valuep, 2) == FAIL) } else if (put_escstr(fd, *valuep, 2) == FAIL)
return FAIL; return FAIL;
} }
@ -7438,10 +7438,10 @@ void vimrc_found(char_u *fname, char_u *envname)
p = FullName_save(fname, FALSE); p = FullName_save(fname, FALSE);
if (p != NULL) { if (p != NULL) {
vim_setenv(envname, p); vim_setenv(envname, p);
free(p); xfree(p);
} }
} else if (dofree) } else if (dofree)
free(p); xfree(p);
} }
} }
@ -7608,7 +7608,7 @@ void save_file_ff(buf_T *buf)
/* Only use free/alloc when necessary, they take time. */ /* Only use free/alloc when necessary, they take time. */
if (buf->b_start_fenc == NULL if (buf->b_start_fenc == NULL
|| STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) { || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) {
free(buf->b_start_fenc); xfree(buf->b_start_fenc);
buf->b_start_fenc = vim_strsave(buf->b_p_fenc); buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
} }
} }

View File

@ -113,7 +113,7 @@ void init_homedir(void)
char_u *var; char_u *var;
/* In case we are called a second time (when 'encoding' changes). */ /* In case we are called a second time (when 'encoding' changes). */
free(homedir); xfree(homedir);
homedir = NULL; homedir = NULL;
var = (char_u *)os_getenv("HOME"); var = (char_u *)os_getenv("HOME");
@ -144,7 +144,7 @@ void init_homedir(void)
void free_homedir(void) void free_homedir(void)
{ {
free(homedir); xfree(homedir);
} }
#endif #endif
@ -304,7 +304,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one,
char_u *p = vim_strsave(var); char_u *p = vim_strsave(var);
if (mustfree) { if (mustfree) {
free(var); xfree(var);
} }
var = p; var = p;
mustfree = true; mustfree = true;
@ -318,7 +318,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one,
char_u *p = vim_strsave_escaped(var, (char_u *)" \t"); char_u *p = vim_strsave_escaped(var, (char_u *)" \t");
if (mustfree) if (mustfree)
free(var); xfree(var);
var = p; var = p;
mustfree = true; mustfree = true;
} }
@ -341,7 +341,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one,
copy_char = false; copy_char = false;
} }
if (mustfree) if (mustfree)
free(var); xfree(var);
} }
if (copy_char) { /* copy at least one char */ if (copy_char) { /* copy at least one char */
@ -380,11 +380,11 @@ static char *vim_version_dir(char *vimdir)
p = concat_fnames((char_u *)vimdir, (char_u *)VIM_VERSION_NODOT, true); p = concat_fnames((char_u *)vimdir, (char_u *)VIM_VERSION_NODOT, true);
if (os_isdir(p)) if (os_isdir(p))
return (char *)p; return (char *)p;
free(p); xfree(p);
p = concat_fnames((char_u *)vimdir, (char_u *)RUNTIME_DIRNAME, true); p = concat_fnames((char_u *)vimdir, (char_u *)RUNTIME_DIRNAME, true);
if (os_isdir(p)) if (os_isdir(p))
return (char *)p; return (char *)p;
free(p); xfree(p);
return NULL; return NULL;
} }
@ -483,7 +483,7 @@ char_u *vim_getenv(char_u *name, bool *mustfree)
p = vim_strnsave(p, (size_t)(pend - p)); p = vim_strnsave(p, (size_t)(pend - p));
if (!os_isdir(p)) { if (!os_isdir(p)) {
free(p); xfree(p);
p = NULL; p = NULL;
} else { } else {
*mustfree = true; *mustfree = true;
@ -634,7 +634,7 @@ void home_replace(buf_T *buf, char_u *src, char_u *dst, int dstlen, bool one)
*dst = NUL; *dst = NUL;
if (homedir_env != homedir_env_orig) if (homedir_env != homedir_env_orig)
free(homedir_env); xfree(homedir_env);
} }
/// Like home_replace, store the replaced string in allocated memory. /// Like home_replace, store the replaced string in allocated memory.
@ -663,7 +663,7 @@ void vim_setenv(char_u *name, char_u *val)
if (*val != NUL && STRICMP(name, "VIMRUNTIME") == 0) { if (*val != NUL && STRICMP(name, "VIMRUNTIME") == 0) {
char_u *buf = concat_str(val, (char_u *)"/lang"); char_u *buf = concat_str(val, (char_u *)"/lang");
bindtextdomain(VIMPACKAGE, (char *)buf); bindtextdomain(VIMPACKAGE, (char *)buf);
free(buf); xfree(buf);
} }
} }
@ -678,7 +678,7 @@ char_u *get_env_name(expand_T *xp, int idx)
char *envname = os_getenvname_at_index((size_t)idx); char *envname = os_getenvname_at_index((size_t)idx);
if (envname) { if (envname) {
STRLCPY(name, envname, ENVNAMELEN); STRLCPY(name, envname, ENVNAMELEN);
free(envname); xfree(envname);
return name; return name;
} else { } else {
return NULL; return NULL;

View File

@ -46,7 +46,6 @@ void event_init(void)
// early msgpack-rpc initialization // early msgpack-rpc initialization
msgpack_rpc_init_method_table(); msgpack_rpc_init_method_table();
msgpack_rpc_helpers_init(); msgpack_rpc_helpers_init();
wstream_init();
// Initialize input events // Initialize input events
input_init(); input_init();
// Timer to wake the event loop if a timeout argument is passed to // Timer to wake the event loop if a timeout argument is passed to

View File

@ -152,14 +152,14 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath)
*abspath = save_absolute_path(buf); *abspath = save_absolute_path(buf);
} }
free(buf); xfree(buf);
return true; return true;
} }
if (*e != ':') { if (*e != ':') {
// End of $PATH without finding any executable called name. // End of $PATH without finding any executable called name.
free(buf); xfree(buf);
return false; return false;
} }

View File

@ -11,6 +11,7 @@
#include "nvim/os/pty_process.h" #include "nvim/os/pty_process.h"
#include "nvim/os/shell.h" #include "nvim/os/shell.h"
#include "nvim/log.h" #include "nvim/log.h"
#include "nvim/memory.h"
struct job { struct job {
// Job id the index in the job table plus one. // Job id the index in the job table plus one.
@ -104,12 +105,12 @@ static inline void job_decref(Job *job)
// Invoke the exit_cb // Invoke the exit_cb
job_exit_callback(job); job_exit_callback(job);
// Free all memory allocated for the job // Free all memory allocated for the job
free(job->proc_stdin->data); xfree(job->proc_stdin->data);
free(job->proc_stdout->data); xfree(job->proc_stdout->data);
free(job->proc_stderr->data); xfree(job->proc_stderr->data);
shell_free_argv(job->opts.argv); shell_free_argv(job->opts.argv);
process_destroy(job); process_destroy(job);
free(job); xfree(job);
} }
} }

View File

@ -72,8 +72,8 @@ void pipe_process_init(Job *job)
void pipe_process_destroy(Job *job) void pipe_process_destroy(Job *job)
{ {
UvProcess *pipeproc = job->process; UvProcess *pipeproc = job->process;
free(pipeproc->proc.data); xfree(pipeproc->proc.data);
free(pipeproc); xfree(pipeproc);
job->process = NULL; job->process = NULL;
} }

View File

@ -65,8 +65,8 @@ void pty_process_init(Job *job) FUNC_ATTR_NONNULL_ALL
void pty_process_destroy(Job *job) FUNC_ATTR_NONNULL_ALL void pty_process_destroy(Job *job) FUNC_ATTR_NONNULL_ALL
{ {
free(job->opts.term_name); xfree(job->opts.term_name);
free(job->process); xfree(job->process);
job->process = NULL; job->process = NULL;
} }

View File

@ -162,8 +162,8 @@ size_t rbuffer_available(RBuffer *rbuffer)
void rbuffer_free(RBuffer *rbuffer) void rbuffer_free(RBuffer *rbuffer)
{ {
free(rbuffer->data); xfree(rbuffer->data);
free(rbuffer); xfree(rbuffer);
} }
/// Creates a new RStream instance. A RStream encapsulates all the boilerplate /// Creates a new RStream instance. A RStream encapsulates all the boilerplate
@ -216,7 +216,7 @@ void rstream_free(RStream *rstream)
} }
rbuffer_free(rstream->buffer); rbuffer_free(rstream->buffer);
free(rstream); xfree(rstream);
} }
/// Sets the underlying `uv_stream_t` instance /// Sets the underlying `uv_stream_t` instance
@ -401,8 +401,8 @@ static void fread_idle_cb(uv_idle_t *handle)
static void close_cb(uv_handle_t *handle) static void close_cb(uv_handle_t *handle)
{ {
free(handle->data); xfree(handle->data);
free(handle); xfree(handle);
} }
static void rbuffer_relocate(RBuffer *rbuffer) static void rbuffer_relocate(RBuffer *rbuffer)

View File

@ -80,11 +80,11 @@ void shell_free_argv(char **argv)
while (*p != NULL) { while (*p != NULL) {
// Free each argument // Free each argument
free(*p); xfree(*p);
p++; p++;
} }
free(argv); xfree(argv);
} }
/// Calls the user-configured 'shell' (p_sh) for running a command or wildcard /// Calls the user-configured 'shell' (p_sh) for running a command or wildcard
@ -128,11 +128,11 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_args)
emsg_silent, emsg_silent,
forward_output); forward_output);
free(input.data); xfree(input.data);
if (output) { if (output) {
(void)write_output(output, nread, true, true); (void)write_output(output, nread, true, true);
free(output); xfree(output);
} }
if (!emsg_silent && status != 0 && !(opts & kShellOptSilent)) { if (!emsg_silent && status != 0 && !(opts & kShellOptSilent)) {
@ -250,7 +250,7 @@ static int shell(const char *cmd,
if (buf.len == 0) { if (buf.len == 0) {
// no data received from the process, return NULL // no data received from the process, return NULL
*output = NULL; *output = NULL;
free(buf.data); xfree(buf.data);
} else { } else {
// NUL-terminate to make the output directly usable as a C string // NUL-terminate to make the output directly usable as a C string
buf.data[buf.len] = NUL; buf.data[buf.len] = NUL;

View File

@ -1,9 +1,8 @@
#include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include <uv.h> #include <uv.h>
#include "nvim/lib/klist.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/vim.h" #include "nvim/vim.h"
#include "nvim/globals.h" #include "nvim/globals.h"
@ -15,10 +14,6 @@
#include "nvim/os/signal.h" #include "nvim/os/signal.h"
#include "nvim/os/event.h" #include "nvim/os/event.h"
#define SignalEventFreer(x)
KMEMPOOL_INIT(SignalEventPool, int, SignalEventFreer)
kmempool_t(SignalEventPool) *signal_event_pool = NULL;
static uv_signal_t spipe, shup, squit, sterm; static uv_signal_t spipe, shup, squit, sterm;
#ifdef SIGPWR #ifdef SIGPWR
static uv_signal_t spwr; static uv_signal_t spwr;
@ -32,7 +27,6 @@ static bool rejecting_deadly;
void signal_init(void) void signal_init(void)
{ {
signal_event_pool = kmp_init(SignalEventPool);
uv_signal_init(uv_default_loop(), &spipe); uv_signal_init(uv_default_loop(), &spipe);
uv_signal_init(uv_default_loop(), &shup); uv_signal_init(uv_default_loop(), &shup);
uv_signal_init(uv_default_loop(), &squit); uv_signal_init(uv_default_loop(), &squit);
@ -119,18 +113,16 @@ static void deadly_signal(int signum)
static void signal_cb(uv_signal_t *handle, int signum) static void signal_cb(uv_signal_t *handle, int signum)
{ {
int *n = kmp_alloc(SignalEventPool, signal_event_pool); assert(signum >= 0);
*n = signum;
event_push((Event) { event_push((Event) {
.handler = on_signal_event, .handler = on_signal_event,
.data = n .data = (void *)(uintptr_t)signum
}, false); }, false);
} }
static void on_signal_event(Event event) static void on_signal_event(Event event)
{ {
int signum = *((int *)event.data); int signum = (int)(uintptr_t)event.data;
kmp_free(SignalEventPool, signal_event_pool, event.data);
switch (signum) { switch (signum) {
#ifdef SIGPWR #ifdef SIGPWR

View File

@ -5,8 +5,6 @@
#include <uv.h> #include <uv.h>
#include "nvim/lib/klist.h"
#include "nvim/os/uv_helpers.h" #include "nvim/os/uv_helpers.h"
#include "nvim/os/wstream.h" #include "nvim/os/wstream.h"
#include "nvim/os/wstream_defs.h" #include "nvim/os/wstream_defs.h"
@ -41,24 +39,10 @@ typedef struct {
uv_write_t uv_req; uv_write_t uv_req;
} WRequest; } WRequest;
#define WRequestFreer(x)
KMEMPOOL_INIT(WRequestPool, WRequest, WRequestFreer)
kmempool_t(WRequestPool) *wrequest_pool = NULL;
#define WBufferFreer(x)
KMEMPOOL_INIT(WBufferPool, WBuffer, WBufferFreer)
kmempool_t(WBufferPool) *wbuffer_pool = NULL;
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/wstream.c.generated.h" # include "os/wstream.c.generated.h"
#endif #endif
/// Initialize pools for reusing commonly created objects
void wstream_init(void)
{
wrequest_pool = kmp_init(WRequestPool);
wbuffer_pool = kmp_init(WBufferPool);
}
/// Creates a new WStream instance. A WStream encapsulates all the boilerplate /// Creates a new WStream instance. A WStream encapsulates all the boilerplate
/// necessary for writing to a libuv stream. /// necessary for writing to a libuv stream.
/// ///
@ -92,7 +76,7 @@ void wstream_free(WStream *wstream) {
uv_close((uv_handle_t *)wstream->stream, close_cb); uv_close((uv_handle_t *)wstream->stream, close_cb);
} else { } else {
handle_set_wstream((uv_handle_t *)wstream->stream, NULL); handle_set_wstream((uv_handle_t *)wstream->stream, NULL);
free(wstream); xfree(wstream);
} }
} else { } else {
wstream->freed = true; wstream->freed = true;
@ -163,7 +147,7 @@ bool wstream_write(WStream *wstream, WBuffer *buffer)
wstream->curmem += buffer->size; wstream->curmem += buffer->size;
WRequest *data = kmp_alloc(WRequestPool, wrequest_pool); WRequest *data = xmalloc(sizeof(WRequest));
data->wstream = wstream; data->wstream = wstream;
data->buffer = buffer; data->buffer = buffer;
data->uv_req.data = data; data->uv_req.data = data;
@ -173,7 +157,7 @@ bool wstream_write(WStream *wstream, WBuffer *buffer)
uvbuf.len = buffer->size; uvbuf.len = buffer->size;
if (uv_write(&data->uv_req, wstream->stream, &uvbuf, 1, write_cb)) { if (uv_write(&data->uv_req, wstream->stream, &uvbuf, 1, write_cb)) {
kmp_free(WRequestPool, wrequest_pool, data); xfree(data);
goto err; goto err;
} }
@ -202,7 +186,7 @@ WBuffer *wstream_new_buffer(char *data,
size_t refcount, size_t refcount,
wbuffer_data_finalizer cb) wbuffer_data_finalizer cb)
{ {
WBuffer *rv = kmp_alloc(WBufferPool, wbuffer_pool); WBuffer *rv = xmalloc(sizeof(WBuffer));
rv->size = size; rv->size = size;
rv->refcount = refcount; rv->refcount = refcount;
rv->cb = cb; rv->cb = cb;
@ -232,11 +216,11 @@ static void write_cb(uv_write_t *req, int status)
if (data->wstream->free_handle) { if (data->wstream->free_handle) {
uv_close((uv_handle_t *)data->wstream->stream, close_cb); uv_close((uv_handle_t *)data->wstream->stream, close_cb);
} else { } else {
free(data->wstream); xfree(data->wstream);
} }
} }
kmp_free(WRequestPool, wrequest_pool, data); xfree(data);
} }
void wstream_release_wbuffer(WBuffer *buffer) void wstream_release_wbuffer(WBuffer *buffer)
@ -246,14 +230,14 @@ void wstream_release_wbuffer(WBuffer *buffer)
buffer->cb(buffer->data); buffer->cb(buffer->data);
} }
kmp_free(WBufferPool, wbuffer_pool, buffer); xfree(buffer);
} }
} }
static void close_cb(uv_handle_t *handle) static void close_cb(uv_handle_t *handle)
{ {
free(handle_get_wstream(handle)); xfree(handle_get_wstream(handle));
free(handle->data); xfree(handle->data);
free(handle); xfree(handle);
} }

View File

@ -435,11 +435,11 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
if (ampersent) if (ampersent)
os_delay(10L, true); os_delay(10L, true);
free(command); xfree(command);
if (i) { /* os_call_shell() failed */ if (i) { /* os_call_shell() failed */
os_remove((char *)tempname); os_remove((char *)tempname);
free(tempname); xfree(tempname);
/* /*
* With interactive completion, the error message is not printed. * With interactive completion, the error message is not printed.
*/ */
@ -472,18 +472,18 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
MSG(_(e_wildexpand)); MSG(_(e_wildexpand));
msg_start(); /* don't overwrite this message */ msg_start(); /* don't overwrite this message */
} }
free(tempname); xfree(tempname);
goto notfound; goto notfound;
} }
int fseek_res = fseek(fd, 0L, SEEK_END); int fseek_res = fseek(fd, 0L, SEEK_END);
if (fseek_res < 0) { if (fseek_res < 0) {
free(tempname); xfree(tempname);
fclose(fd); fclose(fd);
return FAIL; return FAIL;
} }
long long templen = ftell(fd); /* get size of temp file */ long long templen = ftell(fd); /* get size of temp file */
if (templen < 0) { if (templen < 0) {
free(tempname); xfree(tempname);
fclose(fd); fclose(fd);
return FAIL; return FAIL;
} }
@ -501,11 +501,11 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
if (readlen != len) { if (readlen != len) {
/* unexpected read error */ /* unexpected read error */
EMSG2(_(e_notread), tempname); EMSG2(_(e_notread), tempname);
free(tempname); xfree(tempname);
free(buffer); xfree(buffer);
return FAIL; return FAIL;
} }
free(tempname); xfree(tempname);
/* file names are separated with Space */ /* file names are separated with Space */
if (shell_style == STYLE_ECHO) { if (shell_style == STYLE_ECHO) {
@ -574,7 +574,7 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
* /bin/sh will happily expand it to nothing rather than returning an * /bin/sh will happily expand it to nothing rather than returning an
* error; and hey, it's good to check anyway -- webb. * error; and hey, it's good to check anyway -- webb.
*/ */
free(buffer); xfree(buffer);
goto notfound; goto notfound;
} }
*num_file = i; *num_file = i;
@ -628,11 +628,11 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
add_pathsep(p); /* add '/' to a directory name */ add_pathsep(p); /* add '/' to a directory name */
(*file)[j++] = p; (*file)[j++] = p;
} }
free(buffer); xfree(buffer);
*num_file = j; *num_file = j;
if (*num_file == 0) { /* rejected all entries */ if (*num_file == 0) { /* rejected all entries */
free(*file); xfree(*file);
*file = NULL; *file = NULL;
goto notfound; goto notfound;
} }

View File

@ -380,7 +380,7 @@ FullName_save (
} else { } else {
new_fname = vim_strsave(fname); new_fname = vim_strsave(fname);
} }
free(buf); xfree(buf);
return new_fname; return new_fname;
} }
@ -557,7 +557,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
starts_with_dot = (*s == '.'); starts_with_dot = (*s == '.');
pat = file_pat_to_reg_pat(s, e, NULL, FALSE); pat = file_pat_to_reg_pat(s, e, NULL, FALSE);
if (pat == NULL) { if (pat == NULL) {
free(buf); xfree(buf);
return 0; return 0;
} }
@ -574,10 +574,10 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
regmatch.regprog = vim_regcomp(pat, RE_MAGIC); regmatch.regprog = vim_regcomp(pat, RE_MAGIC);
if (flags & (EW_NOERROR | EW_NOTWILD)) if (flags & (EW_NOERROR | EW_NOTWILD))
--emsg_silent; --emsg_silent;
free(pat); xfree(pat);
if (regmatch.regprog == NULL && (flags & EW_NOTWILD) == 0) { if (regmatch.regprog == NULL && (flags & EW_NOTWILD) == 0) {
free(buf); xfree(buf);
return 0; return 0;
} }
@ -634,7 +634,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
os_closedir(&dir); os_closedir(&dir);
} }
free(buf); xfree(buf);
vim_regfree(regmatch.regprog); vim_regfree(regmatch.regprog);
matches = gap->ga_len - start_len; matches = gap->ga_len - start_len;
@ -750,7 +750,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
GA_APPEND(char_u *, gap, vim_strsave(buf)); GA_APPEND(char_u *, gap, vim_strsave(buf));
} }
free(buf); xfree(buf);
} }
/* /*
@ -819,13 +819,13 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
file_pattern[1] = NUL; file_pattern[1] = NUL;
STRCAT(file_pattern, pattern); STRCAT(file_pattern, pattern);
pat = file_pat_to_reg_pat(file_pattern, NULL, NULL, TRUE); pat = file_pat_to_reg_pat(file_pattern, NULL, NULL, TRUE);
free(file_pattern); xfree(file_pattern);
if (pat == NULL) if (pat == NULL)
return; return;
regmatch.rm_ic = TRUE; /* always ignore case */ regmatch.rm_ic = TRUE; /* always ignore case */
regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
free(pat); xfree(pat);
if (regmatch.regprog == NULL) if (regmatch.regprog == NULL)
return; return;
@ -910,16 +910,16 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
add_pathsep(rel_path); add_pathsep(rel_path);
STRCAT(rel_path, short_name); STRCAT(rel_path, short_name);
free(fnames[i]); xfree(fnames[i]);
fnames[i] = rel_path; fnames[i] = rel_path;
sort_again = TRUE; sort_again = TRUE;
os_breakcheck(); os_breakcheck();
} }
free(curdir); xfree(curdir);
for (int i = 0; i < gap->ga_len; i++) for (int i = 0; i < gap->ga_len; i++)
free(in_curdir[i]); xfree(in_curdir[i]);
free(in_curdir); xfree(in_curdir);
ga_clear_strings(&path_ga); ga_clear_strings(&path_ga);
vim_regfree(regmatch.regprog); vim_regfree(regmatch.regprog);
@ -978,7 +978,7 @@ expand_in_path (
ga_init(&path_ga, (int)sizeof(char_u *), 1); ga_init(&path_ga, (int)sizeof(char_u *), 1);
expand_path_option(curdir, &path_ga); expand_path_option(curdir, &path_ga);
free(curdir); xfree(curdir);
if (GA_EMPTY(&path_ga)) if (GA_EMPTY(&path_ga))
return 0; return 0;
@ -986,7 +986,7 @@ expand_in_path (
ga_clear_strings(&path_ga); ga_clear_strings(&path_ga);
globpath(paths, pattern, gap, (flags & EW_ICASE) ? WILD_ICASE : 0); globpath(paths, pattern, gap, (flags & EW_ICASE) ? WILD_ICASE : 0);
free(paths); xfree(paths);
return gap->ga_len; return gap->ga_len;
} }
@ -1110,7 +1110,7 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file,
* found file names and start all over again. * found file names and start all over again.
*/ */
else if (has_env_var(p) || *p == '~') { else if (has_env_var(p) || *p == '~') {
free(p); xfree(p);
ga_clear_strings(&ga); ga_clear_strings(&ga);
i = mch_expand_wildcards(num_pat, pat, num_file, file, i = mch_expand_wildcards(num_pat, pat, num_file, file,
flags | EW_KEEPDOLLAR); flags | EW_KEEPDOLLAR);
@ -1154,13 +1154,13 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file,
addfile(&ga, t, flags | EW_DIR | EW_FILE); addfile(&ga, t, flags | EW_DIR | EW_FILE);
else if (os_file_exists(t)) else if (os_file_exists(t))
addfile(&ga, t, flags); addfile(&ga, t, flags);
free(t); xfree(t);
} }
if (did_expand_in_path && !GA_EMPTY(&ga) && (flags & EW_PATH)) if (did_expand_in_path && !GA_EMPTY(&ga) && (flags & EW_PATH))
uniquefy_paths(&ga, p); uniquefy_paths(&ga, p);
if (p != pat[i]) if (p != pat[i])
free(p); xfree(p);
} }
*num_file = ga.ga_len; *num_file = ga.ga_len;
@ -1206,7 +1206,7 @@ expand_backtick (
else else
buffer = get_cmd_output(cmd, NULL, buffer = get_cmd_output(cmd, NULL,
(flags & EW_SILENT) ? kShellOptSilent : 0, NULL); (flags & EW_SILENT) ? kShellOptSilent : 0, NULL);
free(cmd); xfree(cmd);
if (buffer == NULL) if (buffer == NULL)
return 0; return 0;
@ -1229,7 +1229,7 @@ expand_backtick (
++cmd; ++cmd;
} }
free(buffer); xfree(buffer);
return cnt; return cnt;
} }
@ -1509,13 +1509,13 @@ find_file_name_in_path (
/* Repeat finding the file "count" times. This matters when it /* Repeat finding the file "count" times. This matters when it
* appears several times in the path. */ * appears several times in the path. */
while (file_name != NULL && --count > 0) { while (file_name != NULL && --count > 0) {
free(file_name); xfree(file_name);
file_name = find_file_in_path(ptr, len, options, FALSE, rel_fname); file_name = find_file_in_path(ptr, len, options, FALSE, rel_fname);
} }
} else } else
file_name = vim_strnsave(ptr, len); file_name = vim_strnsave(ptr, len);
free(tofree); xfree(tofree);
return file_name; return file_name;
} }
@ -1793,7 +1793,7 @@ char_u *path_shorten_fname_if_possible(char_u *full_path)
p = full_path; p = full_path;
} }
} }
free(dirname); xfree(dirname);
return p; return p;
} }
@ -1854,8 +1854,8 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char_u ***file,
ret = expand_wildcards(1, &exp_pat, num_file, file, flags); ret = expand_wildcards(1, &exp_pat, num_file, file, flags);
if (eval_pat != NULL) { if (eval_pat != NULL) {
free(exp_pat); xfree(exp_pat);
free(eval_pat); xfree(eval_pat);
} }
return ret; return ret;
@ -1903,13 +1903,13 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file,
break; break;
if (match_file_list(p_wig, (*file)[i], ffname)) { if (match_file_list(p_wig, (*file)[i], ffname)) {
/* remove this matching file from the list */ /* remove this matching file from the list */
free((*file)[i]); xfree((*file)[i]);
for (j = i; j + 1 < *num_file; ++j) for (j = i; j + 1 < *num_file; ++j)
(*file)[j] = (*file)[j + 1]; (*file)[j] = (*file)[j + 1];
--*num_file; --*num_file;
--i; --i;
} }
free(ffname); xfree(ffname);
} }
} }

View File

@ -18,6 +18,7 @@
#include "nvim/screen.h" #include "nvim/screen.h"
#include "nvim/search.h" #include "nvim/search.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/memory.h"
#include "nvim/window.h" #include "nvim/window.h"
#include "nvim/edit.h" #include "nvim/edit.h"
@ -377,12 +378,12 @@ void pum_redraw(void)
} }
} }
screen_puts_len(rt, (int)STRLEN(rt), row, col - size + 1, attr); screen_puts_len(rt, (int)STRLEN(rt), row, col - size + 1, attr);
free(rt_start); xfree(rt_start);
free(st); xfree(st);
col -= width; col -= width;
} else { } else {
screen_puts_len(st, (int)STRLEN(st), row, col, attr); screen_puts_len(st, (int)STRLEN(st), row, col, attr);
free(st); xfree(st);
col += width; col += width;
} }

View File

@ -784,15 +784,15 @@ qf_init_ok:
for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first) { for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first) {
fmt_first = fmt_ptr->next; fmt_first = fmt_ptr->next;
vim_regfree(fmt_ptr->prog); vim_regfree(fmt_ptr->prog);
free(fmt_ptr); xfree(fmt_ptr);
} }
qf_clean_dir_stack(&dir_stack); qf_clean_dir_stack(&dir_stack);
qf_clean_dir_stack(&file_stack); qf_clean_dir_stack(&file_stack);
qf_init_end: qf_init_end:
free(namebuf); xfree(namebuf);
free(errmsg); xfree(errmsg);
free(pattern); xfree(pattern);
free(fmtstr); xfree(fmtstr);
qf_update_buffer(qi); qf_update_buffer(qi);
@ -855,7 +855,7 @@ static void ll_free_all(qf_info_T **pqi)
/* No references to this location list */ /* No references to this location list */
for (i = 0; i < qi->qf_listcount; ++i) for (i = 0; i < qi->qf_listcount; ++i)
qf_free(qi, i); qf_free(qi, i);
free(qi); xfree(qi);
} }
} }
@ -1091,7 +1091,7 @@ static int qf_get_fnum(char_u *directory, char_u *fname)
* directory change. * directory change.
*/ */
if (!os_file_exists(ptr)) { if (!os_file_exists(ptr)) {
free(ptr); xfree(ptr);
directory = qf_guess_filepath(fname); directory = qf_guess_filepath(fname);
if (directory) if (directory)
ptr = concat_fnames(directory, fname, TRUE); ptr = concat_fnames(directory, fname, TRUE);
@ -1100,7 +1100,7 @@ static int qf_get_fnum(char_u *directory, char_u *fname)
} }
/* Use concatenated directory name and file name */ /* Use concatenated directory name and file name */
fnum = buflist_add(ptr, 0); fnum = buflist_add(ptr, 0);
free(ptr); xfree(ptr);
return fnum; return fnum;
} }
return buflist_add(fname, 0); return buflist_add(fname, 0);
@ -1134,7 +1134,7 @@ static char_u *qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr)
ds_new = (*stackptr)->next; ds_new = (*stackptr)->next;
(*stackptr)->dirname = NULL; (*stackptr)->dirname = NULL;
while (ds_new) { while (ds_new) {
free((*stackptr)->dirname); xfree((*stackptr)->dirname);
(*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf, (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf,
TRUE); TRUE);
if (os_isdir((*stackptr)->dirname)) if (os_isdir((*stackptr)->dirname))
@ -1147,13 +1147,13 @@ static char_u *qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr)
while ((*stackptr)->next != ds_new) { while ((*stackptr)->next != ds_new) {
ds_ptr = (*stackptr)->next; ds_ptr = (*stackptr)->next;
(*stackptr)->next = (*stackptr)->next->next; (*stackptr)->next = (*stackptr)->next->next;
free(ds_ptr->dirname); xfree(ds_ptr->dirname);
free(ds_ptr); xfree(ds_ptr);
} }
/* Nothing found -> it must be on top level */ /* Nothing found -> it must be on top level */
if (ds_new == NULL) { if (ds_new == NULL) {
free((*stackptr)->dirname); xfree((*stackptr)->dirname);
(*stackptr)->dirname = vim_strsave(dirbuf); (*stackptr)->dirname = vim_strsave(dirbuf);
} }
} }
@ -1163,7 +1163,7 @@ static char_u *qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr)
else { else {
ds_ptr = *stackptr; ds_ptr = *stackptr;
*stackptr = (*stackptr)->next; *stackptr = (*stackptr)->next;
free(ds_ptr); xfree(ds_ptr);
return NULL; return NULL;
} }
} }
@ -1184,8 +1184,8 @@ static char_u *qf_pop_dir(struct dir_stack_T **stackptr)
if (*stackptr != NULL) { if (*stackptr != NULL) {
ds_ptr = *stackptr; ds_ptr = *stackptr;
*stackptr = (*stackptr)->next; *stackptr = (*stackptr)->next;
free(ds_ptr->dirname); xfree(ds_ptr->dirname);
free(ds_ptr); xfree(ds_ptr);
} }
/* return NEW top element as current dir or NULL if stack is empty*/ /* return NEW top element as current dir or NULL if stack is empty*/
@ -1201,8 +1201,8 @@ static void qf_clean_dir_stack(struct dir_stack_T **stackptr)
while ((ds_ptr = *stackptr) != NULL) { while ((ds_ptr = *stackptr) != NULL) {
*stackptr = (*stackptr)->next; *stackptr = (*stackptr)->next;
free(ds_ptr->dirname); xfree(ds_ptr->dirname);
free(ds_ptr); xfree(ds_ptr);
} }
} }
@ -1239,7 +1239,7 @@ static char_u *qf_guess_filepath(char_u *filename)
ds_ptr = dir_stack->next; ds_ptr = dir_stack->next;
fullname = NULL; fullname = NULL;
while (ds_ptr) { while (ds_ptr) {
free(fullname); xfree(fullname);
fullname = concat_fnames(ds_ptr->dirname, filename, TRUE); fullname = concat_fnames(ds_ptr->dirname, filename, TRUE);
if (os_file_exists(fullname)) if (os_file_exists(fullname))
@ -1248,14 +1248,14 @@ static char_u *qf_guess_filepath(char_u *filename)
ds_ptr = ds_ptr->next; ds_ptr = ds_ptr->next;
} }
free(fullname); xfree(fullname);
/* clean up all dirs we already left */ /* clean up all dirs we already left */
while (dir_stack->next != ds_ptr) { while (dir_stack->next != ds_ptr) {
ds_tmp = dir_stack->next; ds_tmp = dir_stack->next;
dir_stack->next = dir_stack->next->next; dir_stack->next = dir_stack->next->next;
free(ds_tmp->dirname); xfree(ds_tmp->dirname);
free(ds_tmp); xfree(ds_tmp);
} }
return ds_ptr==NULL ? NULL : ds_ptr->dirname; return ds_ptr==NULL ? NULL : ds_ptr->dirname;
@ -1876,10 +1876,10 @@ static void qf_free(qf_info_T *qi, int idx)
while (qi->qf_lists[idx].qf_count) { while (qi->qf_lists[idx].qf_count) {
qfp = qi->qf_lists[idx].qf_start->qf_next; qfp = qi->qf_lists[idx].qf_start->qf_next;
if (qi->qf_lists[idx].qf_title != NULL && !stop) { if (qi->qf_lists[idx].qf_title != NULL && !stop) {
free(qi->qf_lists[idx].qf_start->qf_text); xfree(qi->qf_lists[idx].qf_start->qf_text);
stop = (qi->qf_lists[idx].qf_start == qfp); stop = (qi->qf_lists[idx].qf_start == qfp);
free(qi->qf_lists[idx].qf_start->qf_pattern); xfree(qi->qf_lists[idx].qf_start->qf_pattern);
free(qi->qf_lists[idx].qf_start); xfree(qi->qf_lists[idx].qf_start);
if (stop) if (stop)
/* Somehow qf_count may have an incorrect value, set it to 1 /* Somehow qf_count may have an incorrect value, set it to 1
* to avoid crashing when it's wrong. * to avoid crashing when it's wrong.
@ -1889,7 +1889,7 @@ static void qf_free(qf_info_T *qi, int idx)
qi->qf_lists[idx].qf_start = qfp; qi->qf_lists[idx].qf_start = qfp;
--qi->qf_lists[idx].qf_count; --qi->qf_lists[idx].qf_count;
} }
free(qi->qf_lists[idx].qf_title); xfree(qi->qf_lists[idx].qf_title);
qi->qf_lists[idx].qf_title = NULL; qi->qf_lists[idx].qf_title = NULL;
qi->qf_lists[idx].qf_index = 0; qi->qf_lists[idx].qf_index = 0;
} }
@ -2526,8 +2526,8 @@ void ex_make(exarg_T *eap)
qf_jump(qi, 0, 0, FALSE); /* display first error */ qf_jump(qi, 0, 0, FALSE); /* display first error */
os_remove((char *)fname); os_remove((char *)fname);
free(fname); xfree(fname);
free(cmd); xfree(cmd);
} }
/* /*
@ -2573,7 +2573,7 @@ static char_u *get_mef_name(void)
if (!file_or_link_found) { if (!file_or_link_found) {
break; break;
} }
free(name); xfree(name);
} }
return name; return name;
} }
@ -2834,7 +2834,7 @@ void ex_vimgrep(exarg_T *eap)
msg_outtrans(fname); msg_outtrans(fname);
else { else {
msg_outtrans(p); msg_outtrans(p);
free(p); xfree(p);
} }
msg_clr_eos(); msg_clr_eos();
msg_didout = FALSE; /* overwrite this message */ msg_didout = FALSE; /* overwrite this message */
@ -3021,9 +3021,9 @@ void ex_vimgrep(exarg_T *eap)
} }
theend: theend:
free(dirname_now); xfree(dirname_now);
free(dirname_start); xfree(dirname_start);
free(target_dir); xfree(target_dir);
vim_regfree(regmatch.regprog); vim_regfree(regmatch.regprog);
} }
@ -3091,7 +3091,7 @@ static void restore_start_dir(char_u *dirname_start)
ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd; ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd;
ex_cd(&ea); ex_cd(&ea);
} }
free(dirname_now); xfree(dirname_now);
} }
/* /*
@ -3356,10 +3356,10 @@ int set_errorlist(win_T *wp, list_T *list, int action, char_u *title)
type == NULL ? NUL : *type, type == NULL ? NUL : *type,
valid); valid);
free(filename); xfree(filename);
free(pattern); xfree(pattern);
free(text); xfree(text);
free(type); xfree(type);
if (status == FAIL) { if (status == FAIL) {
retval = FAIL; retval = FAIL;
@ -3599,12 +3599,12 @@ void ex_helpgrep(exarg_T *eap)
) == FAIL) { ) == FAIL) {
got_int = TRUE; got_int = TRUE;
if (line != IObuff) if (line != IObuff)
free(line); xfree(line);
break; break;
} }
} }
if (line != IObuff) if (line != IObuff)
free(line); xfree(line);
++lnum; ++lnum;
line_breakcheck(); line_breakcheck();
} }

View File

@ -1265,7 +1265,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags)
regcode = r->program; regcode = r->program;
regc(REGMAGIC); regc(REGMAGIC);
if (reg(REG_NOPAREN, &flags) == NULL || reg_toolong) { if (reg(REG_NOPAREN, &flags) == NULL || reg_toolong) {
free(r); xfree(r);
if (reg_toolong) if (reg_toolong)
EMSG_RET_NULL(_("E339: Pattern too long")); EMSG_RET_NULL(_("E339: Pattern too long"));
return NULL; return NULL;
@ -1349,7 +1349,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags)
*/ */
static void bt_regfree(regprog_T *prog) static void bt_regfree(regprog_T *prog)
{ {
free(prog); xfree(prog);
} }
/* /*
@ -3236,8 +3236,8 @@ void free_regexp_stuff(void)
{ {
ga_clear(&regstack); ga_clear(&regstack);
ga_clear(&backpos); ga_clear(&backpos);
free(reg_tofree); xfree(reg_tofree);
free(reg_prev_sub); xfree(reg_prev_sub);
} }
#endif #endif
@ -3509,7 +3509,7 @@ theend:
/* Free "reg_tofree" when it's a bit big. /* Free "reg_tofree" when it's a bit big.
* Free regstack and backpos if they are bigger than their initial size. */ * Free regstack and backpos if they are bigger than their initial size. */
if (reg_tofreelen > 400) { if (reg_tofreelen > 400) {
free(reg_tofree); xfree(reg_tofree);
reg_tofree = NULL; reg_tofree = NULL;
} }
if (regstack.ga_maxlen > REGSTACK_INITIAL) if (regstack.ga_maxlen > REGSTACK_INITIAL)
@ -3551,8 +3551,8 @@ void unref_extmatch(reg_extmatch_T *em)
if (em != NULL && --em->refcnt <= 0) { if (em != NULL && --em->refcnt <= 0) {
for (i = 0; i < NSUBEXP; ++i) for (i = 0; i < NSUBEXP; ++i)
free(em->matches[i]); xfree(em->matches[i]);
free(em); xfree(em);
} }
} }
@ -5642,7 +5642,7 @@ static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T e
len = (int)STRLEN(regline); len = (int)STRLEN(regline);
if (reg_tofree == NULL || len >= (int)reg_tofreelen) { if (reg_tofree == NULL || len >= (int)reg_tofreelen) {
len += 50; /* get some extra */ len += 50; /* get some extra */
free(reg_tofree); xfree(reg_tofree);
reg_tofree = xmalloc(len); reg_tofree = xmalloc(len);
reg_tofreelen = len; reg_tofreelen = len;
} }
@ -6382,7 +6382,7 @@ char_u *regtilde(char_u *source, int magic)
STRCPY(tmpsub + len + prevlen, p + 1); STRCPY(tmpsub + len + prevlen, p + 1);
if (newsub != source) /* already allocated newsub */ if (newsub != source) /* already allocated newsub */
free(newsub); xfree(newsub);
newsub = tmpsub; newsub = tmpsub;
p = newsub + len + prevlen; p = newsub + len + prevlen;
} else if (magic) } else if (magic)
@ -6398,7 +6398,7 @@ char_u *regtilde(char_u *source, int magic)
} }
} }
free(reg_prev_sub); xfree(reg_prev_sub);
if (newsub != source) /* newsub was allocated, just keep it */ if (newsub != source) /* newsub was allocated, just keep it */
reg_prev_sub = newsub; reg_prev_sub = newsub;
else /* no ~ found, need to save newsub */ else /* no ~ found, need to save newsub */
@ -6494,14 +6494,14 @@ static int vim_regsub_both(char_u *source, char_u *dest, int copy, int magic, in
if (eval_result != NULL) { if (eval_result != NULL) {
STRCPY(dest, eval_result); STRCPY(dest, eval_result);
dst += STRLEN(eval_result); dst += STRLEN(eval_result);
free(eval_result); xfree(eval_result);
eval_result = NULL; eval_result = NULL;
} }
} else { } else {
win_T *save_reg_win; win_T *save_reg_win;
int save_ireg_ic; int save_ireg_ic;
free(eval_result); xfree(eval_result);
/* The expression may contain substitute(), which calls us /* The expression may contain substitute(), which calls us
* recursively. Make sure submatch() gets the text from the first * recursively. Make sure submatch() gets the text from the first
@ -6542,7 +6542,7 @@ static int vim_regsub_both(char_u *source, char_u *dest, int copy, int magic, in
if (had_backslash && backslash) { if (had_backslash && backslash) {
/* Backslashes will be consumed, need to double them. */ /* Backslashes will be consumed, need to double them. */
s = vim_strsave_escaped(eval_result, (char_u *)"\\"); s = vim_strsave_escaped(eval_result, (char_u *)"\\");
free(eval_result); xfree(eval_result);
eval_result = s; eval_result = s;
} }
@ -7073,7 +7073,7 @@ static int vim_regexec_both(regmatch_T *rmp, char_u *line, colnr_T col, bool nl)
result = rmp->regprog->engine->regexec_nl(rmp, line, col, nl); result = rmp->regprog->engine->regexec_nl(rmp, line, col, nl);
} }
free(pat); xfree(pat);
p_re = save_p_re; p_re = save_p_re;
} }
@ -7127,7 +7127,7 @@ long vim_regexec_multi(
tm); tm);
} }
free(pat); xfree(pat);
p_re = save_p_re; p_re = save_p_re;
} }

View File

@ -2886,7 +2886,7 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size)
if (stackp < stack) \ if (stackp < stack) \
{ \ { \
st_error(postfix, end, p); \ st_error(postfix, end, p); \
free(stack); \ xfree(stack); \
return NULL; \ return NULL; \
} }
@ -3317,13 +3317,13 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size)
e = POP(); e = POP();
if (stackp != stack) { if (stackp != stack) {
free(stack); xfree(stack);
EMSG_RET_NULL(_("E875: (NFA regexp) (While converting from postfix to NFA)," EMSG_RET_NULL(_("E875: (NFA regexp) (While converting from postfix to NFA),"
"too many states left on stack")); "too many states left on stack"));
} }
if (istate >= nstate) { if (istate >= nstate) {
free(stack); xfree(stack);
EMSG_RET_NULL(_("E876: (NFA regexp) " EMSG_RET_NULL(_("E876: (NFA regexp) "
"Not enough space to store the whole NFA ")); "Not enough space to store the whole NFA "));
} }
@ -3337,7 +3337,7 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size)
ret = e.start; ret = e.start;
theend: theend:
free(stack); xfree(stack);
return ret; return ret;
#undef POP1 #undef POP1
@ -4195,7 +4195,7 @@ addstate_here (
memmove(&(newl[listidx + count]), memmove(&(newl[listidx + count]),
&(l->t[listidx + 1]), &(l->t[listidx + 1]),
sizeof(nfa_thread_T) * (l->n - count - listidx - 1)); sizeof(nfa_thread_T) * (l->n - count - listidx - 1));
free(l->t); xfree(l->t);
l->t = newl; l->t = newl;
} else { } else {
/* make space for new states, then move them from the /* make space for new states, then move them from the
@ -6033,9 +6033,9 @@ nextchar:
theend: theend:
/* Free memory */ /* Free memory */
free(list[0].t); xfree(list[0].t);
free(list[1].t); xfree(list[1].t);
free(listids); xfree(listids);
#undef ADD_STATE_IF_MATCH #undef ADD_STATE_IF_MATCH
#ifdef NFA_REGEXP_DEBUG_LOG #ifdef NFA_REGEXP_DEBUG_LOG
fclose(debug); fclose(debug);
@ -6340,13 +6340,13 @@ static regprog_T *nfa_regcomp(char_u *expr, int re_flags)
nfa_regengine.expr = NULL; nfa_regengine.expr = NULL;
out: out:
free(post_start); xfree(post_start);
post_start = post_ptr = post_end = NULL; post_start = post_ptr = post_end = NULL;
state_ptr = NULL; state_ptr = NULL;
return (regprog_T *)prog; return (regprog_T *)prog;
fail: fail:
free(prog); xfree(prog);
prog = NULL; prog = NULL;
#ifdef REGEXP_DEBUG #ifdef REGEXP_DEBUG
nfa_postfix_dump(expr, FAIL); nfa_postfix_dump(expr, FAIL);
@ -6361,9 +6361,9 @@ fail:
static void nfa_regfree(regprog_T *prog) static void nfa_regfree(regprog_T *prog)
{ {
if (prog != NULL) { if (prog != NULL) {
free(((nfa_regprog_T *)prog)->match_text); xfree(((nfa_regprog_T *)prog)->match_text);
free(((nfa_regprog_T *)prog)->pattern); xfree(((nfa_regprog_T *)prog)->pattern);
free(prog); xfree(prog);
} }
} }

View File

@ -1905,7 +1905,7 @@ static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T
} }
if (text != buf) if (text != buf)
free(text); xfree(text);
/* /*
* 6. set highlighting for the Visual area an other text. * 6. set highlighting for the Visual area an other text.
@ -3015,7 +3015,7 @@ win_line (
--n_extra; --n_extra;
} else { } else {
if (p_extra_free != NULL) { if (p_extra_free != NULL) {
free(p_extra_free); xfree(p_extra_free);
p_extra_free = NULL; p_extra_free = NULL;
} }
/* /*
@ -4700,7 +4700,7 @@ win_redr_status_matches (
} }
win_redraw_last_status(topframe); win_redraw_last_status(topframe);
free(buf); xfree(buf);
} }
/* /*
@ -4915,7 +4915,7 @@ get_keymap_str (
sprintf((char *)buf, "<%s>", p); sprintf((char *)buf, "<%s>", p);
else else
buf[0] = NUL; buf[0] = NUL;
free(s); xfree(s);
} }
return buf[0] != NUL; return buf[0] != NUL;
} }
@ -5021,14 +5021,14 @@ win_redr_custom (
width = build_stl_str_hl(ewp, buf, sizeof(buf), width = build_stl_str_hl(ewp, buf, sizeof(buf),
stl, use_sandbox, stl, use_sandbox,
fillchar, maxwidth, hltab, tabtab); fillchar, maxwidth, hltab, tabtab);
free(stl); xfree(stl);
ewp->w_p_crb = p_crb_save; ewp->w_p_crb = p_crb_save;
/* Make all characters printable. */ /* Make all characters printable. */
p = transstr(buf); p = transstr(buf);
len = STRLCPY(buf, p, sizeof(buf)); len = STRLCPY(buf, p, sizeof(buf));
len = (size_t)len < sizeof(buf) ? len : (int)sizeof(buf) - 1; len = (size_t)len < sizeof(buf) ? len : (int)sizeof(buf) - 1;
free(p); xfree(p);
/* fill up with "fillchar" */ /* fill up with "fillchar" */
while (width < maxwidth && len < (int)sizeof(buf) - 1) { while (width < maxwidth && len < (int)sizeof(buf) - 1) {
@ -5999,23 +5999,23 @@ retry:
* and over again. */ * and over again. */
done_outofmem_msg = TRUE; done_outofmem_msg = TRUE;
} }
free(new_ScreenLines); xfree(new_ScreenLines);
new_ScreenLines = NULL; new_ScreenLines = NULL;
free(new_ScreenLinesUC); xfree(new_ScreenLinesUC);
new_ScreenLinesUC = NULL; new_ScreenLinesUC = NULL;
for (i = 0; i < p_mco; ++i) { for (i = 0; i < p_mco; ++i) {
free(new_ScreenLinesC[i]); xfree(new_ScreenLinesC[i]);
new_ScreenLinesC[i] = NULL; new_ScreenLinesC[i] = NULL;
} }
free(new_ScreenLines2); xfree(new_ScreenLines2);
new_ScreenLines2 = NULL; new_ScreenLines2 = NULL;
free(new_ScreenAttrs); xfree(new_ScreenAttrs);
new_ScreenAttrs = NULL; new_ScreenAttrs = NULL;
free(new_LineOffset); xfree(new_LineOffset);
new_LineOffset = NULL; new_LineOffset = NULL;
free(new_LineWraps); xfree(new_LineWraps);
new_LineWraps = NULL; new_LineWraps = NULL;
free(new_TabPageIdxs); xfree(new_TabPageIdxs);
new_TabPageIdxs = NULL; new_TabPageIdxs = NULL;
} else { } else {
done_outofmem_msg = FALSE; done_outofmem_msg = FALSE;
@ -6126,15 +6126,15 @@ void free_screenlines(void)
{ {
int i; int i;
free(ScreenLinesUC); xfree(ScreenLinesUC);
for (i = 0; i < Screen_mco; ++i) for (i = 0; i < Screen_mco; ++i)
free(ScreenLinesC[i]); xfree(ScreenLinesC[i]);
free(ScreenLines2); xfree(ScreenLines2);
free(ScreenLines); xfree(ScreenLines);
free(ScreenAttrs); xfree(ScreenAttrs);
free(LineOffset); xfree(LineOffset);
free(LineWraps); xfree(LineWraps);
free(TabPageIdxs); xfree(TabPageIdxs);
} }
void screenclear(void) void screenclear(void)

View File

@ -179,7 +179,7 @@ search_regcomp (
add_to_history(HIST_SEARCH, pat, TRUE, NUL); add_to_history(HIST_SEARCH, pat, TRUE, NUL);
if (mr_pattern_alloced) { if (mr_pattern_alloced) {
free(mr_pattern); xfree(mr_pattern);
mr_pattern_alloced = FALSE; mr_pattern_alloced = FALSE;
} }
@ -249,7 +249,7 @@ char_u *reverse_text(char_u *s) FUNC_ATTR_NONNULL_RET
void save_re_pat(int idx, char_u *pat, int magic) void save_re_pat(int idx, char_u *pat, int magic)
{ {
if (spats[idx].pat != pat) { if (spats[idx].pat != pat) {
free(spats[idx].pat); xfree(spats[idx].pat);
spats[idx].pat = vim_strsave(pat); spats[idx].pat = vim_strsave(pat);
spats[idx].magic = magic; spats[idx].magic = magic;
spats[idx].no_scs = no_smartcase; spats[idx].no_scs = no_smartcase;
@ -284,10 +284,10 @@ void save_search_patterns(void)
void restore_search_patterns(void) void restore_search_patterns(void)
{ {
if (--save_level == 0) { if (--save_level == 0) {
free(spats[0].pat); xfree(spats[0].pat);
spats[0] = saved_spats[0]; spats[0] = saved_spats[0];
set_vv_searchforward(); set_vv_searchforward();
free(spats[1].pat); xfree(spats[1].pat);
spats[1] = saved_spats[1]; spats[1] = saved_spats[1];
last_idx = saved_last_idx; last_idx = saved_last_idx;
SET_NO_HLSEARCH(saved_no_hlsearch); SET_NO_HLSEARCH(saved_no_hlsearch);
@ -297,11 +297,11 @@ void restore_search_patterns(void)
#if defined(EXITFREE) #if defined(EXITFREE)
void free_search_patterns(void) void free_search_patterns(void)
{ {
free(spats[0].pat); xfree(spats[0].pat);
free(spats[1].pat); xfree(spats[1].pat);
if (mr_pattern_alloced) { if (mr_pattern_alloced) {
free(mr_pattern); xfree(mr_pattern);
mr_pattern_alloced = FALSE; mr_pattern_alloced = FALSE;
mr_pattern = NULL; mr_pattern = NULL;
} }
@ -377,7 +377,7 @@ void reset_search_dir(void)
*/ */
void set_last_search_pat(const char_u *s, int idx, int magic, int setlast) void set_last_search_pat(const char_u *s, int idx, int magic, int setlast)
{ {
free(spats[idx].pat); xfree(spats[idx].pat);
/* An empty string means that nothing should be matched. */ /* An empty string means that nothing should be matched. */
if (*s == NUL) if (*s == NUL)
spats[idx].pat = NULL; spats[idx].pat = NULL;
@ -393,7 +393,7 @@ void set_last_search_pat(const char_u *s, int idx, int magic, int setlast)
if (setlast) if (setlast)
last_idx = idx; last_idx = idx;
if (save_level) { if (save_level) {
free(saved_spats[idx].pat); xfree(saved_spats[idx].pat);
saved_spats[idx] = spats[0]; saved_spats[idx] = spats[0];
if (spats[idx].pat == NULL) if (spats[idx].pat == NULL)
saved_spats[idx].pat = NULL; saved_spats[idx].pat = NULL;
@ -1075,17 +1075,17 @@ int do_search(
* left, but do reverse the text. */ * left, but do reverse the text. */
if (curwin->w_p_rl && *curwin->w_p_rlc == 's') { if (curwin->w_p_rl && *curwin->w_p_rlc == 's') {
char_u *r = reverse_text(trunc != NULL ? trunc : msgbuf); char_u *r = reverse_text(trunc != NULL ? trunc : msgbuf);
free(trunc); xfree(trunc);
trunc = r; trunc = r;
} }
if (trunc != NULL) { if (trunc != NULL) {
msg_outtrans(trunc); msg_outtrans(trunc);
free(trunc); xfree(trunc);
} else } else
msg_outtrans(msgbuf); msg_outtrans(msgbuf);
msg_clr_eos(); msg_clr_eos();
msg_check(); msg_check();
free(msgbuf); xfree(msgbuf);
gotocmdline(FALSE); gotocmdline(FALSE);
ui_flush(); ui_flush();
@ -1203,7 +1203,7 @@ int do_search(
end_do_search: end_do_search:
if ((options & SEARCH_KEEP) || cmdmod.keeppatterns) if ((options & SEARCH_KEEP) || cmdmod.keeppatterns)
spats[0].off = old_off; spats[0].off = old_off;
free(strcopy); xfree(strcopy);
return retval; return retval;
} }
@ -3246,8 +3246,8 @@ again:
r = do_searchpair(spat, (char_u *)"", epat, FORWARD, (char_u *)"", r = do_searchpair(spat, (char_u *)"", epat, FORWARD, (char_u *)"",
0, NULL, (linenr_T)0, 0L); 0, NULL, (linenr_T)0, 0L);
free(spat); xfree(spat);
free(epat); xfree(epat);
if (r < 1 || lt(curwin->w_cursor, old_end)) { if (r < 1 || lt(curwin->w_cursor, old_end)) {
/* Can't find other end or it's before the previous end. Could be a /* Can't find other end or it's before the previous end. Could be a
@ -4006,7 +4006,7 @@ find_pattern_in_path (
/* ignore case according to p_ic, p_scs and pat */ /* ignore case according to p_ic, p_scs and pat */
regmatch.rm_ic = ignorecase(pat); regmatch.rm_ic = ignorecase(pat);
regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
free(pat); xfree(pat);
if (regmatch.regprog == NULL) if (regmatch.regprog == NULL)
goto fpip_end; goto fpip_end;
} }
@ -4070,7 +4070,7 @@ find_pattern_in_path (
prev_fname = NULL; prev_fname = NULL;
} }
} }
free(new_fname); xfree(new_fname);
new_fname = NULL; new_fname = NULL;
already_searched = TRUE; already_searched = TRUE;
break; break;
@ -4173,17 +4173,17 @@ find_pattern_in_path (
bigger[i + max_path_depth] = files[i]; bigger[i + max_path_depth] = files[i];
old_files += max_path_depth; old_files += max_path_depth;
max_path_depth *= 2; max_path_depth *= 2;
free(files); xfree(files);
files = bigger; files = bigger;
} }
if ((files[depth + 1].fp = mch_fopen((char *)new_fname, "r")) if ((files[depth + 1].fp = mch_fopen((char *)new_fname, "r"))
== NULL) == NULL)
free(new_fname); xfree(new_fname);
else { else {
if (++depth == old_files) { if (++depth == old_files) {
// Something wrong. We will forget one of our already visited files // Something wrong. We will forget one of our already visited files
// now. // now.
free(files[old_files].name); xfree(files[old_files].name);
++old_files; ++old_files;
} }
files[depth].name = curr_fname = new_fname; files[depth].name = curr_fname = new_fname;
@ -4491,11 +4491,11 @@ exit_matched:
/* Close any files that are still open. */ /* Close any files that are still open. */
for (i = 0; i <= depth; i++) { for (i = 0; i <= depth; i++) {
fclose(files[i].fp); fclose(files[i].fp);
free(files[i].name); xfree(files[i].name);
} }
for (i = old_files; i < max_path_depth; i++) for (i = old_files; i < max_path_depth; i++)
free(files[i].name); xfree(files[i].name);
free(files); xfree(files);
if (type == CHECK_PATH) { if (type == CHECK_PATH) {
if (!did_show) { if (!did_show) {
@ -4518,7 +4518,7 @@ exit_matched:
msg_end(); msg_end();
fpip_end: fpip_end:
free(file_line); xfree(file_line);
vim_regfree(regmatch.regprog); vim_regfree(regmatch.regprog);
vim_regfree(incl_regmatch.regprog); vim_regfree(incl_regmatch.regprog);
vim_regfree(def_regmatch.regprog); vim_regfree(def_regmatch.regprog);
@ -4629,7 +4629,7 @@ int read_viminfo_search_pattern(vir_T *virp, int force)
if (force || spats[idx].pat == NULL) { if (force || spats[idx].pat == NULL) {
val = viminfo_readstring(virp, (int)(lp - virp->vir_line + 1), TRUE); val = viminfo_readstring(virp, (int)(lp - virp->vir_line + 1), TRUE);
set_last_search_pat(val, idx, magic, setlast); set_last_search_pat(val, idx, magic, setlast);
free(val); xfree(val);
spats[idx].no_scs = no_scs; spats[idx].no_scs = no_scs;
spats[idx].off.line = off_line; spats[idx].off.line = off_line;
spats[idx].off.end = off_end; spats[idx].off.end = off_end;

View File

@ -2097,7 +2097,7 @@ spell_move_to (
len = (int)STRLEN(line); len = (int)STRLEN(line);
if (buflen < len + MAXWLEN + 2) { if (buflen < len + MAXWLEN + 2) {
free(buf); xfree(buf);
buflen = len + MAXWLEN + 2; buflen = len + MAXWLEN + 2;
buf = xmalloc(buflen); buf = xmalloc(buflen);
} }
@ -2172,7 +2172,7 @@ spell_move_to (
if (dir == FORWARD) { if (dir == FORWARD) {
// No need to search further. // No need to search further.
wp->w_cursor = found_pos; wp->w_cursor = found_pos;
free(buf); xfree(buf);
if (attrp != NULL) if (attrp != NULL)
*attrp = attr; *attrp = attr;
return len; return len;
@ -2195,7 +2195,7 @@ spell_move_to (
if (dir == BACKWARD && found_pos.lnum != 0) { if (dir == BACKWARD && found_pos.lnum != 0) {
// Use the last match in the line (before the cursor). // Use the last match in the line (before the cursor).
wp->w_cursor = found_pos; wp->w_cursor = found_pos;
free(buf); xfree(buf);
return found_len; return found_len;
} }
@ -2259,7 +2259,7 @@ spell_move_to (
line_breakcheck(); line_breakcheck();
} }
free(buf); xfree(buf);
return 0; return 0;
} }
@ -2376,26 +2376,26 @@ static slang_T *slang_alloc(char_u *lang)
// Free the contents of an slang_T and the structure itself. // Free the contents of an slang_T and the structure itself.
static void slang_free(slang_T *lp) static void slang_free(slang_T *lp)
{ {
free(lp->sl_name); xfree(lp->sl_name);
free(lp->sl_fname); xfree(lp->sl_fname);
slang_clear(lp); slang_clear(lp);
free(lp); xfree(lp);
} }
/// Frees a salitem_T /// Frees a salitem_T
static void free_salitem(salitem_T *smp) { static void free_salitem(salitem_T *smp) {
free(smp->sm_lead); xfree(smp->sm_lead);
// Don't free sm_oneof and sm_rules, they point into sm_lead. // Don't free sm_oneof and sm_rules, they point into sm_lead.
free(smp->sm_to); xfree(smp->sm_to);
free(smp->sm_lead_w); xfree(smp->sm_lead_w);
free(smp->sm_oneof_w); xfree(smp->sm_oneof_w);
free(smp->sm_to_w); xfree(smp->sm_to_w);
} }
/// Frees a fromto_T /// Frees a fromto_T
static void free_fromto(fromto_T *ftp) { static void free_fromto(fromto_T *ftp) {
free(ftp->ft_from); xfree(ftp->ft_from);
free(ftp->ft_to); xfree(ftp->ft_to);
} }
// Clear an slang_T so that the file can be reloaded. // Clear an slang_T so that the file can be reloaded.
@ -2403,18 +2403,18 @@ static void slang_clear(slang_T *lp)
{ {
garray_T *gap; garray_T *gap;
free(lp->sl_fbyts); xfree(lp->sl_fbyts);
lp->sl_fbyts = NULL; lp->sl_fbyts = NULL;
free(lp->sl_kbyts); xfree(lp->sl_kbyts);
lp->sl_kbyts = NULL; lp->sl_kbyts = NULL;
free(lp->sl_pbyts); xfree(lp->sl_pbyts);
lp->sl_pbyts = NULL; lp->sl_pbyts = NULL;
free(lp->sl_fidxs); xfree(lp->sl_fidxs);
lp->sl_fidxs = NULL; lp->sl_fidxs = NULL;
free(lp->sl_kidxs); xfree(lp->sl_kidxs);
lp->sl_kidxs = NULL; lp->sl_kidxs = NULL;
free(lp->sl_pidxs); xfree(lp->sl_pidxs);
lp->sl_pidxs = NULL; lp->sl_pidxs = NULL;
GA_DEEP_CLEAR(&lp->sl_rep, fromto_T, free_fromto); GA_DEEP_CLEAR(&lp->sl_rep, fromto_T, free_fromto);
@ -2433,25 +2433,25 @@ static void slang_clear(slang_T *lp)
vim_regfree(lp->sl_prefprog[i]); vim_regfree(lp->sl_prefprog[i]);
} }
lp->sl_prefixcnt = 0; lp->sl_prefixcnt = 0;
free(lp->sl_prefprog); xfree(lp->sl_prefprog);
lp->sl_prefprog = NULL; lp->sl_prefprog = NULL;
free(lp->sl_info); xfree(lp->sl_info);
lp->sl_info = NULL; lp->sl_info = NULL;
free(lp->sl_midword); xfree(lp->sl_midword);
lp->sl_midword = NULL; lp->sl_midword = NULL;
vim_regfree(lp->sl_compprog); vim_regfree(lp->sl_compprog);
free(lp->sl_comprules); xfree(lp->sl_comprules);
free(lp->sl_compstartflags); xfree(lp->sl_compstartflags);
free(lp->sl_compallflags); xfree(lp->sl_compallflags);
lp->sl_compprog = NULL; lp->sl_compprog = NULL;
lp->sl_comprules = NULL; lp->sl_comprules = NULL;
lp->sl_compstartflags = NULL; lp->sl_compstartflags = NULL;
lp->sl_compallflags = NULL; lp->sl_compallflags = NULL;
free(lp->sl_syllable); xfree(lp->sl_syllable);
lp->sl_syllable = NULL; lp->sl_syllable = NULL;
ga_clear(&lp->sl_syl_items); ga_clear(&lp->sl_syl_items);
@ -2474,9 +2474,9 @@ static void slang_clear(slang_T *lp)
// Clear the info from the .sug file in "lp". // Clear the info from the .sug file in "lp".
static void slang_clear_sug(slang_T *lp) static void slang_clear_sug(slang_T *lp)
{ {
free(lp->sl_sbyts); xfree(lp->sl_sbyts);
lp->sl_sbyts = NULL; lp->sl_sbyts = NULL;
free(lp->sl_sidxs); xfree(lp->sl_sidxs);
lp->sl_sidxs = NULL; lp->sl_sidxs = NULL;
close_spellbuf(lp->sl_sugbuf); close_spellbuf(lp->sl_sugbuf);
lp->sl_sugbuf = NULL; lp->sl_sugbuf = NULL;
@ -2642,7 +2642,7 @@ spell_load_file (
if (p == NULL) if (p == NULL)
goto endFAIL; goto endFAIL;
set_map_str(lp, p); set_map_str(lp, p);
free(p); xfree(p);
break; break;
case SN_WORDS: case SN_WORDS:
@ -2799,7 +2799,7 @@ static int read_charflags_section(FILE *fd)
// <folcharslen> <folchars> // <folcharslen> <folchars>
fol = read_cnt_string(fd, 2, &follen); fol = read_cnt_string(fd, 2, &follen);
if (follen < 0) { if (follen < 0) {
free(flags); xfree(flags);
return follen; return follen;
} }
@ -2807,8 +2807,8 @@ static int read_charflags_section(FILE *fd)
if (flags != NULL && fol != NULL) if (flags != NULL && fol != NULL)
set_spell_charflags(flags, flagslen, fol); set_spell_charflags(flags, flagslen, fol);
free(flags); xfree(flags);
free(fol); xfree(fol);
// When <charflagslen> is zero then <fcharlen> must also be zero. // When <charflagslen> is zero then <fcharlen> must also be zero.
if ((flags == NULL) != (fol == NULL)) if ((flags == NULL) != (fol == NULL))
@ -2878,7 +2878,7 @@ static int read_rep_section(FILE *fd, garray_T *gap, short *first)
return SP_FORMERROR; return SP_FORMERROR;
ftp->ft_to = read_cnt_string(fd, 1, &c); ftp->ft_to = read_cnt_string(fd, 1, &c);
if (c <= 0) { if (c <= 0) {
free(ftp->ft_from); xfree(ftp->ft_from);
if (c < 0) if (c < 0)
return c; return c;
return SP_FORMERROR; return SP_FORMERROR;
@ -2973,7 +2973,7 @@ static int read_sal_section(FILE *fd, slang_T *slang)
// <saltolen> <salto> // <saltolen> <salto>
smp->sm_to = read_cnt_string(fd, 1, &ccnt); smp->sm_to = read_cnt_string(fd, 1, &ccnt);
if (ccnt < 0) { if (ccnt < 0) {
free(smp->sm_lead); xfree(smp->sm_lead);
return ccnt; return ccnt;
} }
@ -3136,7 +3136,7 @@ static int read_sofo_section(FILE *fd, slang_T *slang)
// <sofotolen> <sofoto> // <sofotolen> <sofoto>
to = read_cnt_string(fd, 2, &cnt); to = read_cnt_string(fd, 2, &cnt);
if (cnt < 0) { if (cnt < 0) {
free(from); xfree(from);
return cnt; return cnt;
} }
@ -3148,8 +3148,8 @@ static int read_sofo_section(FILE *fd, slang_T *slang)
else else
res = 0; res = 0;
free(from); xfree(from);
free(to); xfree(to);
return res; return res;
} }
@ -3250,7 +3250,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len)
while (todo-- > 0) { while (todo-- > 0) {
c = getc(fd); // <compflags> c = getc(fd); // <compflags>
if (c == EOF) { if (c == EOF) {
free(pat); xfree(pat);
return SP_TRUNCERROR; return SP_TRUNCERROR;
} }
@ -3281,7 +3281,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len)
// Copy flag to "sl_comprules", unless we run into a wildcard. // Copy flag to "sl_comprules", unless we run into a wildcard.
if (crp != NULL) { if (crp != NULL) {
if (c == '?' || c == '+' || c == '*') { if (c == '?' || c == '+' || c == '*') {
free(slang->sl_comprules); xfree(slang->sl_comprules);
slang->sl_comprules = NULL; slang->sl_comprules = NULL;
crp = NULL; crp = NULL;
} else } else
@ -3311,7 +3311,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len)
*crp = NUL; *crp = NUL;
slang->sl_compprog = vim_regcomp(pat, RE_MAGIC + RE_STRING + RE_STRICT); slang->sl_compprog = vim_regcomp(pat, RE_MAGIC + RE_STRING + RE_STRICT);
free(pat); xfree(pat);
if (slang->sl_compprog == NULL) if (slang->sl_compprog == NULL)
return SP_FORMERROR; return SP_FORMERROR;
@ -3961,7 +3961,7 @@ char_u *did_set_spelllang(win_T *wp)
} }
theend: theend:
free(spl_copy); xfree(spl_copy);
recursive = false; recursive = false;
redraw_win_later(wp, NOT_VALID); redraw_win_later(wp, NOT_VALID);
return ret_msg; return ret_msg;
@ -3971,7 +3971,7 @@ theend:
static void clear_midword(win_T *wp) static void clear_midword(win_T *wp)
{ {
memset(wp->w_s->b_spell_ismw, 0, 256); memset(wp->w_s->b_spell_ismw, 0, 256);
free(wp->w_s->b_spell_ismw_mb); xfree(wp->w_s->b_spell_ismw_mb);
wp->w_s->b_spell_ismw_mb = NULL; wp->w_s->b_spell_ismw_mb = NULL;
} }
@ -4000,7 +4000,7 @@ static void use_midword(slang_T *lp, win_T *wp)
// Append multi-byte chars to "b_spell_ismw_mb". // Append multi-byte chars to "b_spell_ismw_mb".
n = (int)STRLEN(wp->w_s->b_spell_ismw_mb); n = (int)STRLEN(wp->w_s->b_spell_ismw_mb);
bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l); bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l);
free(wp->w_s->b_spell_ismw_mb); xfree(wp->w_s->b_spell_ismw_mb);
wp->w_s->b_spell_ismw_mb = bp; wp->w_s->b_spell_ismw_mb = bp;
STRLCPY(bp + n, p, l + 1); STRLCPY(bp + n, p, l + 1);
} }
@ -4124,7 +4124,7 @@ void spell_delete_wordlist(void)
os_remove((char *)int_wordlist); os_remove((char *)int_wordlist);
int_wordlist_spl(fname); int_wordlist_spl(fname);
os_remove((char *)fname); os_remove((char *)fname);
free(int_wordlist); xfree(int_wordlist);
int_wordlist = NULL; int_wordlist = NULL;
} }
} }
@ -4147,9 +4147,9 @@ void spell_free_all(void)
spell_delete_wordlist(); spell_delete_wordlist();
free(repl_to); xfree(repl_to);
repl_to = NULL; repl_to = NULL;
free(repl_from); xfree(repl_from);
repl_from = NULL; repl_from = NULL;
} }
@ -4392,7 +4392,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
continue; continue;
// Convert from "SET" to 'encoding' when needed. // Convert from "SET" to 'encoding' when needed.
free(pc); xfree(pc);
if (spin->si_conv.vc_type != CONV_NONE) { if (spin->si_conv.vc_type != CONV_NONE) {
pc = string_convert(&spin->si_conv, rline, NULL); pc = string_convert(&spin->si_conv, rline, NULL);
if (pc == NULL) { if (pc == NULL) {
@ -5005,9 +5005,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
(void)set_spell_chartab(fol, low, upp); (void)set_spell_chartab(fol, low, upp);
} }
free(fol); xfree(fol);
free(low); xfree(low);
free(upp); xfree(upp);
} }
// Use compound specifications of the .aff file for the spell info. // Use compound specifications of the .aff file for the spell info.
@ -5070,7 +5070,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
spin->si_midword = midword; spin->si_midword = midword;
} }
free(pc); xfree(pc);
fclose(fd); fclose(fd);
return aff; return aff;
} }
@ -5344,7 +5344,7 @@ static void spell_free_aff(afffile_T *aff)
affheader_T *ah; affheader_T *ah;
affentry_T *ae; affentry_T *ae;
free(aff->af_enc); xfree(aff->af_enc);
// All this trouble to free the "ae_prog" items... // All this trouble to free the "ae_prog" items...
for (ht = &aff->af_pref;; ht = &aff->af_suff) { for (ht = &aff->af_pref;; ht = &aff->af_suff) {
@ -5461,7 +5461,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile)
// Skip non-ASCII words when "spin->si_ascii" is true. // Skip non-ASCII words when "spin->si_ascii" is true.
if (spin->si_ascii && has_non_ascii(w)) { if (spin->si_ascii && has_non_ascii(w)) {
++non_ascii; ++non_ascii;
free(pc); xfree(pc);
continue; continue;
} }
@ -5483,7 +5483,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile)
dw = getroom_save(spin, w); dw = getroom_save(spin, w);
if (dw == NULL) { if (dw == NULL) {
retval = FAIL; retval = FAIL;
free(pc); xfree(pc);
break; break;
} }
@ -5542,7 +5542,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile)
retval = FAIL; retval = FAIL;
} }
free(pc); xfree(pc);
} }
if (duplicate > 0) if (duplicate > 0)
@ -5938,7 +5938,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname)
rline[l] = NUL; rline[l] = NUL;
// Convert from "/encoding={encoding}" to 'encoding' when needed. // Convert from "/encoding={encoding}" to 'encoding' when needed.
free(pc); xfree(pc);
if (spin->si_conv.vc_type != CONV_NONE) { if (spin->si_conv.vc_type != CONV_NONE) {
pc = string_convert(&spin->si_conv, rline, NULL); pc = string_convert(&spin->si_conv, rline, NULL);
if (pc == NULL) { if (pc == NULL) {
@ -5974,7 +5974,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname)
p_enc) == FAIL) p_enc) == FAIL)
smsg((char_u *)_("Conversion in %s not supported: from %s to %s"), smsg((char_u *)_("Conversion in %s not supported: from %s to %s"),
fname, line, p_enc); fname, line, p_enc);
free(enc); xfree(enc);
spin->si_conv.vc_fail = true; spin->si_conv.vc_fail = true;
} }
continue; continue;
@ -6054,7 +6054,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname)
did_word = true; did_word = true;
} }
free(pc); xfree(pc);
fclose(fd); fclose(fd);
if (spin->si_ascii && non_ascii > 0) { if (spin->si_ascii && non_ascii > 0) {
@ -6123,7 +6123,7 @@ static void free_blocks(sblock_T *bl)
while (bl != NULL) { while (bl != NULL) {
next = bl->sb_next; next = bl->sb_next;
free(bl); xfree(bl);
bl = next; bl = next;
} }
} }
@ -7167,7 +7167,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname)
sug_write(spin, fname); sug_write(spin, fname);
theend: theend:
free(fname); xfree(fname);
if (free_slang) if (free_slang)
slang_free(slang); slang_free(slang);
free_blocks(spin->si_blocks); free_blocks(spin->si_blocks);
@ -7514,7 +7514,7 @@ static void close_spellbuf(buf_T *buf)
{ {
if (buf != NULL) { if (buf != NULL) {
ml_close(buf, TRUE); ml_close(buf, TRUE);
free(buf); xfree(buf);
} }
} }
@ -7737,8 +7737,8 @@ mkspell (
} }
theend: theend:
free(fname); xfree(fname);
free(wfname); xfree(wfname);
} }
// Display a message for spell file processing when 'verbose' is set or using // Display a message for spell file processing when 'verbose' is set or using
@ -7812,7 +7812,7 @@ spell_add_word (
break; break;
if (*spf == NUL) { if (*spf == NUL) {
EMSGN(_("E765: 'spellfile' does not have %" PRId64 " entries"), idx); EMSGN(_("E765: 'spellfile' does not have %" PRId64 " entries"), idx);
free(fnamebuf); xfree(fnamebuf);
return; return;
} }
} }
@ -7823,7 +7823,7 @@ spell_add_word (
buf = NULL; buf = NULL;
if (buf != NULL && bufIsChanged(buf)) { if (buf != NULL && bufIsChanged(buf)) {
EMSG(_(e_bufloaded)); EMSG(_(e_bufloaded));
free(fnamebuf); xfree(fnamebuf);
return; return;
} }
@ -7908,7 +7908,7 @@ spell_add_word (
redraw_all_later(SOME_VALID); redraw_all_later(SOME_VALID);
} }
free(fnamebuf); xfree(fnamebuf);
} }
// Initialize 'spellfile' for the current buffer. // Initialize 'spellfile' for the current buffer.
@ -7977,7 +7977,7 @@ static void init_spellfile(void)
aspath = false; aspath = false;
} }
free(buf); xfree(buf);
} }
} }
@ -8464,9 +8464,9 @@ void spell_suggest(int count)
smsg((char_u *)_("Sorry, only %" PRId64 " suggestions"), smsg((char_u *)_("Sorry, only %" PRId64 " suggestions"),
(int64_t)sug.su_ga.ga_len); (int64_t)sug.su_ga.ga_len);
} else { } else {
free(repl_from); xfree(repl_from);
repl_from = NULL; repl_from = NULL;
free(repl_to); xfree(repl_to);
repl_to = NULL; repl_to = NULL;
// When 'rightleft' is set the list is drawn right-left. // When 'rightleft' is set the list is drawn right-left.
@ -8638,7 +8638,7 @@ static bool check_need_cap(linenr_T lnum, colnr_T col)
} }
} }
free(line_copy); xfree(line_copy);
return need_cap; return need_cap;
} }
@ -8696,7 +8696,7 @@ void ex_spellrepall(exarg_T *eap)
p_ws = save_ws; p_ws = save_ws;
curwin->w_cursor = pos; curwin->w_cursor = pos;
free(frompat); xfree(frompat);
if (sub_nsubs == 0) if (sub_nsubs == 0)
EMSG2(_("E753: Not found: %s"), repl_from); EMSG2(_("E753: Not found: %s"), repl_from);
@ -8849,7 +8849,7 @@ spell_find_suggest (
} }
} }
free(sps_copy); xfree(sps_copy);
if (do_combine) if (do_combine)
// Combine the two list of suggestions. This must be done last, // Combine the two list of suggestions. This must be done last,
@ -9181,7 +9181,7 @@ static void tree_count_words(char_u *byts, idx_T *idxs)
// Free the info put in "*su" by spell_find_suggest(). // Free the info put in "*su" by spell_find_suggest().
static void spell_find_cleanup(suginfo_T *su) static void spell_find_cleanup(suginfo_T *su)
{ {
# define FREE_SUG_WORD(sug) free(sug->st_word) # define FREE_SUG_WORD(sug) xfree(sug->st_word)
// Free the suggestions. // Free the suggestions.
GA_DEEP_CLEAR(&su->su_ga, suggest_T, FREE_SUG_WORD); GA_DEEP_CLEAR(&su->su_ga, suggest_T, FREE_SUG_WORD);
GA_DEEP_CLEAR(&su->su_sga, suggest_T, FREE_SUG_WORD); GA_DEEP_CLEAR(&su->su_sga, suggest_T, FREE_SUG_WORD);
@ -10866,7 +10866,7 @@ static void score_combine(suginfo_T *su)
if (j == ga.ga_len) if (j == ga.ga_len)
stp[ga.ga_len++] = SUG(*gap, i); stp[ga.ga_len++] = SUG(*gap, i);
else else
free(p); xfree(p);
} }
} }
} }
@ -10877,7 +10877,7 @@ static void score_combine(suginfo_T *su)
// Truncate the list to the number of suggestions that will be displayed. // Truncate the list to the number of suggestions that will be displayed.
if (ga.ga_len > su->su_maxcount) { if (ga.ga_len > su->su_maxcount) {
for (int i = su->su_maxcount; i < ga.ga_len; ++i) { for (int i = su->su_maxcount; i < ga.ga_len; ++i) {
free(stp[i].st_word); xfree(stp[i].st_word);
} }
ga.ga_len = su->su_maxcount; ga.ga_len = su->su_maxcount;
} }
@ -11004,7 +11004,7 @@ static void suggest_try_soundalike_finish(void)
todo = (int)slang->sl_sounddone.ht_used; todo = (int)slang->sl_sounddone.ht_used;
for (hi = slang->sl_sounddone.ht_array; todo > 0; ++hi) for (hi = slang->sl_sounddone.ht_array; todo > 0; ++hi)
if (!HASHITEM_EMPTY(hi)) { if (!HASHITEM_EMPTY(hi)) {
free(HI2SFT(hi)); xfree(HI2SFT(hi));
--todo; --todo;
} }
@ -11328,7 +11328,7 @@ static void set_map_str(slang_T *lp, char_u *map)
// This should have been checked when generating the .spl // This should have been checked when generating the .spl
// file. // file.
EMSG(_("E783: duplicate char in MAP entry")); EMSG(_("E783: duplicate char in MAP entry"));
free(b); xfree(b);
} }
} else } else
lp->sl_map_array[c] = headc; lp->sl_map_array[c] = headc;
@ -11511,7 +11511,7 @@ check_suggestions (
(void)spell_check(curwin, longword, &attr, NULL, false); (void)spell_check(curwin, longword, &attr, NULL, false);
if (attr != HLF_COUNT) { if (attr != HLF_COUNT) {
// Remove this entry. // Remove this entry.
free(stp[i].st_word); xfree(stp[i].st_word);
--gap->ga_len; --gap->ga_len;
if (i < gap->ga_len) if (i < gap->ga_len)
memmove(stp + i, stp + i + 1, memmove(stp + i, stp + i + 1,
@ -11608,7 +11608,7 @@ cleanup_suggestions (
// Truncate the list to the number of suggestions that will be displayed. // Truncate the list to the number of suggestions that will be displayed.
if (gap->ga_len > keep) { if (gap->ga_len > keep) {
for (int i = keep; i < gap->ga_len; ++i) { for (int i = keep; i < gap->ga_len; ++i) {
free(stp[i].st_word); xfree(stp[i].st_word);
} }
gap->ga_len = keep; gap->ga_len = keep;
return stp[keep - 1].st_score; return stp[keep - 1].st_score;
@ -12548,7 +12548,7 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword)
} }
i = CNT(badlen - 1, goodlen - 1); i = CNT(badlen - 1, goodlen - 1);
free(cnt); xfree(cnt);
return i; return i;
} }
@ -12906,7 +12906,7 @@ void ex_spelldump(exarg_T *eap)
// enable spelling locally in the new window // enable spelling locally in the new window
set_option_value((char_u*)"spell", TRUE, (char_u*)"", OPT_LOCAL); set_option_value((char_u*)"spell", TRUE, (char_u*)"", OPT_LOCAL);
set_option_value((char_u*)"spl", dummy, spl, OPT_LOCAL); set_option_value((char_u*)"spl", dummy, spl, OPT_LOCAL);
free(spl); xfree(spl);
if (!bufempty() || !buf_valid(curbuf)) if (!bufempty() || !buf_valid(curbuf))
return; return;

View File

@ -269,7 +269,7 @@ char_u *strup_save(const char_u *orig)
memcpy(s, res, (size_t)(p - res)); memcpy(s, res, (size_t)(p - res));
STRCPY(s + (p - res) + newl, p + l); STRCPY(s + (p - res) + newl, p + l);
p = s + (p - res); p = s + (p - res);
free(res); xfree(res);
res = s; res = s;
} }

View File

@ -959,7 +959,7 @@ static void syn_stack_free_block(synblock_T *block)
if (block->b_sst_array != NULL) { 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); clear_syn_state(p);
free(block->b_sst_array); xfree(block->b_sst_array);
block->b_sst_array = NULL; block->b_sst_array = NULL;
block->b_sst_len = 0; block->b_sst_len = 0;
} }
@ -1044,7 +1044,7 @@ static void syn_stack_alloc(void)
to->sst_next = to + 1; to->sst_next = to + 1;
(sstp + len - 1)->sst_next = NULL; (sstp + len - 1)->sst_next = NULL;
free(syn_block->b_sst_array); xfree(syn_block->b_sst_array);
syn_block->b_sst_array = sstp; syn_block->b_sst_array = sstp;
syn_block->b_sst_len = len; syn_block->b_sst_len = len;
} }
@ -3054,7 +3054,7 @@ void syntax_clear(synblock_T *block)
vim_regfree(block->b_syn_linecont_prog); vim_regfree(block->b_syn_linecont_prog);
block->b_syn_linecont_prog = NULL; block->b_syn_linecont_prog = NULL;
free(block->b_syn_linecont_pat); xfree(block->b_syn_linecont_pat);
block->b_syn_linecont_pat = NULL; block->b_syn_linecont_pat = NULL;
block->b_syn_folditems = 0; block->b_syn_folditems = 0;
@ -3073,7 +3073,7 @@ void reset_synblock(win_T *wp)
{ {
if (wp->w_s != &wp->w_buffer->b_s) { if (wp->w_s != &wp->w_buffer->b_s) {
syntax_clear(wp->w_s); syntax_clear(wp->w_s);
free(wp->w_s); xfree(wp->w_s);
wp->w_s = &wp->w_buffer->b_s; wp->w_s = &wp->w_buffer->b_s;
} }
} }
@ -3097,7 +3097,7 @@ static void syntax_sync_clear(void)
vim_regfree(curwin->w_s->b_syn_linecont_prog); vim_regfree(curwin->w_s->b_syn_linecont_prog);
curwin->w_s->b_syn_linecont_prog = NULL; curwin->w_s->b_syn_linecont_prog = NULL;
free(curwin->w_s->b_syn_linecont_pat); xfree(curwin->w_s->b_syn_linecont_pat);
curwin->w_s->b_syn_linecont_pat = NULL; curwin->w_s->b_syn_linecont_pat = NULL;
syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */
@ -3125,13 +3125,13 @@ static void syn_remove_pattern(synblock_T *block, int idx)
*/ */
static void syn_clear_pattern(synblock_T *block, int i) static void syn_clear_pattern(synblock_T *block, int i)
{ {
free(SYN_ITEMS(block)[i].sp_pattern); xfree(SYN_ITEMS(block)[i].sp_pattern);
vim_regfree(SYN_ITEMS(block)[i].sp_prog); vim_regfree(SYN_ITEMS(block)[i].sp_prog);
/* Only free sp_cont_list and sp_next_list of first start pattern */ /* Only free sp_cont_list and sp_next_list of first start pattern */
if (i == 0 || SYN_ITEMS(block)[i - 1].sp_type != SPTYPE_START) { if (i == 0 || SYN_ITEMS(block)[i - 1].sp_type != SPTYPE_START) {
free(SYN_ITEMS(block)[i].sp_cont_list); xfree(SYN_ITEMS(block)[i].sp_cont_list);
free(SYN_ITEMS(block)[i].sp_next_list); xfree(SYN_ITEMS(block)[i].sp_next_list);
free(SYN_ITEMS(block)[i].sp_syn.cont_in_list); xfree(SYN_ITEMS(block)[i].sp_syn.cont_in_list);
} }
} }
@ -3140,9 +3140,9 @@ static void syn_clear_pattern(synblock_T *block, int i)
*/ */
static void syn_clear_cluster(synblock_T *block, int i) static void syn_clear_cluster(synblock_T *block, int i)
{ {
free(SYN_CLSTR(block)[i].scl_name); xfree(SYN_CLSTR(block)[i].scl_name);
free(SYN_CLSTR(block)[i].scl_name_u); xfree(SYN_CLSTR(block)[i].scl_name_u);
free(SYN_CLSTR(block)[i].scl_list); xfree(SYN_CLSTR(block)[i].scl_list);
} }
/* /*
@ -3198,7 +3198,7 @@ static void syn_cmd_clear(exarg_T *eap, int syncing)
*/ */
short scl_id = id - SYNID_CLUSTER; short scl_id = id - SYNID_CLUSTER;
free(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); xfree(SYN_CLSTR(curwin->w_s)[scl_id].scl_list);
SYN_CLSTR(curwin->w_s)[scl_id].scl_list = NULL; SYN_CLSTR(curwin->w_s)[scl_id].scl_list = NULL;
} }
} else { } else {
@ -3760,9 +3760,9 @@ static void syn_clear_keyword(int id, hashtab_T *ht)
hi->hi_key = KE2HIKEY(kp_next); hi->hi_key = KE2HIKEY(kp_next);
} else } else
kp_prev->ke_next = kp_next; kp_prev->ke_next = kp_next;
free(kp->next_list); xfree(kp->next_list);
free(kp->k_syn.cont_in_list); xfree(kp->k_syn.cont_in_list);
free(kp); xfree(kp);
kp = kp_next; kp = kp_next;
} else { } else {
kp_prev = kp; kp_prev = kp;
@ -3789,9 +3789,9 @@ static void clear_keywtab(hashtab_T *ht)
--todo; --todo;
for (kp = HI2KE(hi); kp != NULL; kp = kp_next) { for (kp = HI2KE(hi); kp != NULL; kp = kp_next) {
kp_next = kp->ke_next; kp_next = kp->ke_next;
free(kp->next_list); xfree(kp->next_list);
free(kp->k_syn.cont_in_list); xfree(kp->k_syn.cont_in_list);
free(kp); xfree(kp);
} }
} }
} }
@ -4011,12 +4011,12 @@ get_syn_options (
} }
if (i < 0) { if (i < 0) {
EMSG2(_("E394: Didn't find region item for %s"), gname); EMSG2(_("E394: Didn't find region item for %s"), gname);
free(gname); xfree(gname);
return NULL; return NULL;
} }
} }
free(gname); xfree(gname);
arg = skipwhite(arg); arg = skipwhite(arg);
} else if (flagtab[fidx].flags == HL_FOLD } else if (flagtab[fidx].flags == HL_FOLD
&& foldmethodIsSyntax(curwin)) && foldmethodIsSyntax(curwin))
@ -4208,9 +4208,9 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing)
} }
} }
free(keyword_copy); xfree(keyword_copy);
free(syn_opt_arg.cont_in_list); xfree(syn_opt_arg.cont_in_list);
free(syn_opt_arg.next_list); xfree(syn_opt_arg.next_list);
} }
if (rest != NULL) if (rest != NULL)
@ -4311,10 +4311,10 @@ syn_cmd_match (
* Something failed, free the allocated memory. * Something failed, free the allocated memory.
*/ */
vim_regfree(item.sp_prog); vim_regfree(item.sp_prog);
free(item.sp_pattern); xfree(item.sp_pattern);
free(syn_opt_arg.cont_list); xfree(syn_opt_arg.cont_list);
free(syn_opt_arg.cont_in_list); xfree(syn_opt_arg.cont_in_list);
free(syn_opt_arg.next_list); xfree(syn_opt_arg.next_list);
if (rest == NULL) if (rest == NULL)
EMSG2(_(e_invarg2), arg); EMSG2(_(e_invarg2), arg);
@ -4388,7 +4388,7 @@ syn_cmd_region (
key_end = rest; key_end = rest;
while (*key_end && !vim_iswhite(*key_end) && *key_end != '=') while (*key_end && !vim_iswhite(*key_end) && *key_end != '=')
++key_end; ++key_end;
free(key); xfree(key);
key = vim_strnsave_up(rest, (int)(key_end - rest)); key = vim_strnsave_up(rest, (int)(key_end - rest));
if (STRCMP(key, "MATCHGROUP") == 0) if (STRCMP(key, "MATCHGROUP") == 0)
item = ITEM_MATCHGROUP; item = ITEM_MATCHGROUP;
@ -4456,7 +4456,7 @@ syn_cmd_region (
++pat_count; ++pat_count;
} }
} }
free(key); xfree(key);
if (illegal || not_enough) if (illegal || not_enough)
rest = NULL; rest = NULL;
@ -4530,17 +4530,17 @@ syn_cmd_region (
for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp_next) { for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp_next) {
if (!success) { if (!success) {
vim_regfree(ppp->pp_synp->sp_prog); vim_regfree(ppp->pp_synp->sp_prog);
free(ppp->pp_synp->sp_pattern); xfree(ppp->pp_synp->sp_pattern);
} }
free(ppp->pp_synp); xfree(ppp->pp_synp);
ppp_next = ppp->pp_next; ppp_next = ppp->pp_next;
free(ppp); xfree(ppp);
} }
if (!success) { if (!success) {
free(syn_opt_arg.cont_list); xfree(syn_opt_arg.cont_list);
free(syn_opt_arg.cont_in_list); xfree(syn_opt_arg.cont_in_list);
free(syn_opt_arg.next_list); xfree(syn_opt_arg.next_list);
if (not_enough) if (not_enough)
EMSG2(_("E399: Not enough arguments: syntax region %s"), arg); EMSG2(_("E399: Not enough arguments: syntax region %s"), arg);
else if (illegal || rest == NULL) else if (illegal || rest == NULL)
@ -4580,11 +4580,11 @@ static void syn_combine_list(short **clstr1, short **clstr2, int list_op)
return; return;
if (*clstr1 == NULL || list_op == CLUSTER_REPLACE) { if (*clstr1 == NULL || list_op == CLUSTER_REPLACE) {
if (list_op == CLUSTER_REPLACE) if (list_op == CLUSTER_REPLACE)
free(*clstr1); xfree(*clstr1);
if (list_op == CLUSTER_REPLACE || list_op == CLUSTER_ADD) if (list_op == CLUSTER_REPLACE || list_op == CLUSTER_ADD)
*clstr1 = *clstr2; *clstr1 = *clstr2;
else else
free(*clstr2); xfree(*clstr2);
return; return;
} }
@ -4668,8 +4668,8 @@ static void syn_combine_list(short **clstr1, short **clstr2, int list_op)
/* /*
* Finally, put the new list in place. * Finally, put the new list in place.
*/ */
free(*clstr1); xfree(*clstr1);
free(*clstr2); xfree(*clstr2);
*clstr1 = clstr; *clstr1 = clstr;
} }
@ -4688,7 +4688,7 @@ static int syn_scl_name2id(char_u *name)
break; break;
} }
} }
free(name_u); xfree(name_u);
return i < 0 ? 0 : i + SYNID_CLUSTER; return i < 0 ? 0 : i + SYNID_CLUSTER;
} }
@ -4699,7 +4699,7 @@ static int syn_scl_namen2id(char_u *linep, int len)
{ {
char_u *name = vim_strnsave(linep, len); char_u *name = vim_strnsave(linep, len);
int id = syn_scl_name2id(name); int id = syn_scl_name2id(name);
free(name); xfree(name);
return id; return id;
} }
@ -4721,7 +4721,7 @@ static int syn_check_cluster(char_u *pp, int len)
if (id == 0) /* doesn't exist yet */ if (id == 0) /* doesn't exist yet */
id = syn_add_cluster(name); id = syn_add_cluster(name);
else else
free(name); xfree(name);
return id; return id;
} }
@ -4743,7 +4743,7 @@ static int syn_add_cluster(char_u *name)
int len = curwin->w_s->b_syn_clusters.ga_len; int len = curwin->w_s->b_syn_clusters.ga_len;
if (len >= MAX_CLUSTER_ID) { if (len >= MAX_CLUSTER_ID) {
EMSG((char_u *)_("E848: Too many syntax clusters")); EMSG((char_u *)_("E848: Too many syntax clusters"));
free(name); xfree(name);
return 0; return 0;
} }
@ -4945,7 +4945,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing)
while (!ends_excmd(*arg_start)) { while (!ends_excmd(*arg_start)) {
arg_end = skiptowhite(arg_start); arg_end = skiptowhite(arg_start);
next_arg = skipwhite(arg_end); next_arg = skipwhite(arg_end);
free(key); xfree(key);
key = vim_strnsave_up(arg_start, (int)(arg_end - arg_start)); key = vim_strnsave_up(arg_start, (int)(arg_end - arg_start));
if (STRCMP(key, "CCOMMENT") == 0) { if (STRCMP(key, "CCOMMENT") == 0) {
if (!eap->skip) if (!eap->skip)
@ -5013,7 +5013,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing)
syn_clear_time(&curwin->w_s->b_syn_linecont_time); syn_clear_time(&curwin->w_s->b_syn_linecont_time);
if (curwin->w_s->b_syn_linecont_prog == NULL) { if (curwin->w_s->b_syn_linecont_prog == NULL) {
free(curwin->w_s->b_syn_linecont_pat); xfree(curwin->w_s->b_syn_linecont_pat);
curwin->w_s->b_syn_linecont_pat = NULL; curwin->w_s->b_syn_linecont_pat = NULL;
finished = TRUE; finished = TRUE;
break; break;
@ -5035,7 +5035,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing)
} }
arg_start = next_arg; arg_start = next_arg;
} }
free(key); xfree(key);
if (illegal) if (illegal)
EMSG2(_("E404: Illegal arguments: %s"), arg_start); EMSG2(_("E404: Illegal arguments: %s"), arg_start);
else if (!finished) { else if (!finished) {
@ -5109,13 +5109,13 @@ get_id_list (
if (TOUPPER_ASC(**arg) != 'C') { if (TOUPPER_ASC(**arg) != 'C') {
EMSG2(_("E407: %s not allowed here"), name + 1); EMSG2(_("E407: %s not allowed here"), name + 1);
failed = TRUE; failed = TRUE;
free(name); xfree(name);
break; break;
} }
if (count != 0) { if (count != 0) {
EMSG2(_("E408: %s must be first in contains list"), name + 1); EMSG2(_("E408: %s must be first in contains list"), name + 1);
failed = TRUE; failed = TRUE;
free(name); xfree(name);
break; break;
} }
if (name[1] == 'A') if (name[1] == 'A')
@ -5142,7 +5142,7 @@ get_id_list (
regmatch.regprog = vim_regcomp(name, RE_MAGIC); regmatch.regprog = vim_regcomp(name, RE_MAGIC);
if (regmatch.regprog == NULL) { if (regmatch.regprog == NULL) {
failed = TRUE; failed = TRUE;
free(name); xfree(name);
break; break;
} }
@ -5156,7 +5156,7 @@ get_id_list (
* "contains=a.*b,axb". * "contains=a.*b,axb".
* Go back to first round */ * Go back to first round */
if (count >= total_count) { if (count >= total_count) {
free(retval); xfree(retval);
round = 1; round = 1;
} else } else
retval[count] = i + 1; retval[count] = i + 1;
@ -5168,7 +5168,7 @@ get_id_list (
vim_regfree(regmatch.regprog); vim_regfree(regmatch.regprog);
} }
} }
free(name); xfree(name);
if (id == 0) { if (id == 0) {
EMSG2(_("E409: Unknown group name: %s"), p); EMSG2(_("E409: Unknown group name: %s"), p);
failed = TRUE; failed = TRUE;
@ -5178,7 +5178,7 @@ get_id_list (
if (round == 2) { if (round == 2) {
/* Got more items than expected, go back to first round */ /* Got more items than expected, go back to first round */
if (count >= total_count) { if (count >= total_count) {
free(retval); xfree(retval);
round = 1; round = 1;
} else } else
retval[count] = id; retval[count] = id;
@ -5201,14 +5201,14 @@ get_id_list (
*arg = p; *arg = p;
if (failed || retval == NULL) { if (failed || retval == NULL) {
free(retval); xfree(retval);
return FAIL; return FAIL;
} }
if (*list == NULL) if (*list == NULL)
*list = retval; *list = retval;
else else
free(retval); /* list already found, don't overwrite it */ xfree(retval); /* list already found, don't overwrite it */
return OK; return OK;
} }
@ -5387,7 +5387,7 @@ void ex_syntax(exarg_T *eap)
break; break;
} }
} }
free(subcmd_name); xfree(subcmd_name);
if (eap->skip) if (eap->skip)
--emsg_skip; --emsg_skip;
} }
@ -5427,7 +5427,7 @@ void ex_ownsyntax(exarg_T *eap)
do_unlet((char_u *)"b:current_syntax", TRUE); do_unlet((char_u *)"b:current_syntax", TRUE);
else { else {
set_internal_string_var((char_u *)"b:current_syntax", old_value); set_internal_string_var((char_u *)"b:current_syntax", old_value);
free(old_value); xfree(old_value);
} }
} }
@ -5862,7 +5862,7 @@ init_highlight (
// p invalid, so copy it. // p invalid, so copy it.
char_u *copy_p = vim_strsave(p); char_u *copy_p = vim_strsave(p);
bool okay = load_colors(copy_p); bool okay = load_colors(copy_p);
free(copy_p); xfree(copy_p);
if (okay) { if (okay) {
return; return;
} }
@ -5943,7 +5943,7 @@ int load_colors(char_u *name)
buf = xmalloc(STRLEN(name) + 12); buf = xmalloc(STRLEN(name) + 12);
sprintf((char *)buf, "colors/%s.vim", name); sprintf((char *)buf, "colors/%s.vim", name);
retval = source_runtime(buf, FALSE); retval = source_runtime(buf, FALSE);
free(buf); xfree(buf);
apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf); apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf);
recursive = FALSE; recursive = FALSE;
@ -6145,7 +6145,7 @@ do_highlight (
*/ */
while (*linep && !vim_iswhite(*linep) && *linep != '=') while (*linep && !vim_iswhite(*linep) && *linep != '=')
++linep; ++linep;
free(key); xfree(key);
key = vim_strnsave_up(key_start, (int)(linep - key_start)); key = vim_strnsave_up(key_start, (int)(linep - key_start));
linep = skipwhite(linep); linep = skipwhite(linep);
@ -6189,7 +6189,7 @@ do_highlight (
error = TRUE; error = TRUE;
break; break;
} }
free(arg); xfree(arg);
arg = vim_strnsave(arg_start, (int)(linep - arg_start)); arg = vim_strnsave(arg_start, (int)(linep - arg_start));
if (*linep == '\'') if (*linep == '\'')
@ -6394,7 +6394,7 @@ do_highlight (
if (!init) if (!init)
HL_TABLE()[idx].sg_set |= SG_GUI; HL_TABLE()[idx].sg_set |= SG_GUI;
free(HL_TABLE()[idx].sg_rgb_fg_name); xfree(HL_TABLE()[idx].sg_rgb_fg_name);
if (STRCMP(arg, "NONE")) { if (STRCMP(arg, "NONE")) {
HL_TABLE()[idx].sg_rgb_fg_name = (uint8_t *)xstrdup((char *)arg); HL_TABLE()[idx].sg_rgb_fg_name = (uint8_t *)xstrdup((char *)arg);
HL_TABLE()[idx].sg_rgb_fg = name_to_color(arg); HL_TABLE()[idx].sg_rgb_fg = name_to_color(arg);
@ -6412,7 +6412,7 @@ do_highlight (
if (!init) if (!init)
HL_TABLE()[idx].sg_set |= SG_GUI; HL_TABLE()[idx].sg_set |= SG_GUI;
free(HL_TABLE()[idx].sg_rgb_bg_name); xfree(HL_TABLE()[idx].sg_rgb_bg_name);
if (STRCMP(arg, "NONE") != 0) { if (STRCMP(arg, "NONE") != 0) {
HL_TABLE()[idx].sg_rgb_bg_name = (uint8_t *)xstrdup((char *)arg); HL_TABLE()[idx].sg_rgb_bg_name = (uint8_t *)xstrdup((char *)arg);
HL_TABLE()[idx].sg_rgb_bg = name_to_color(arg); HL_TABLE()[idx].sg_rgb_bg = name_to_color(arg);
@ -6462,8 +6462,8 @@ do_highlight (
HL_TABLE()[idx].sg_scriptID = current_SID; HL_TABLE()[idx].sg_scriptID = current_SID;
redraw_all_later(NOT_VALID); redraw_all_later(NOT_VALID);
} }
free(key); xfree(key);
free(arg); xfree(arg);
/* Only call highlight_changed() once, after sourcing a syntax file */ /* Only call highlight_changed() once, after sourcing a syntax file */
need_highlight_changed = TRUE; need_highlight_changed = TRUE;
@ -6474,8 +6474,8 @@ void free_highlight(void)
{ {
for (int i = 0; i < highlight_ga.ga_len; ++i) { for (int i = 0; i < highlight_ga.ga_len; ++i) {
highlight_clear(i); highlight_clear(i);
free(HL_TABLE()[i].sg_name); xfree(HL_TABLE()[i].sg_name);
free(HL_TABLE()[i].sg_name_u); xfree(HL_TABLE()[i].sg_name_u);
} }
ga_clear(&highlight_ga); ga_clear(&highlight_ga);
} }
@ -6522,9 +6522,9 @@ static void highlight_clear(int idx)
HL_TABLE()[idx].sg_gui = 0; HL_TABLE()[idx].sg_gui = 0;
HL_TABLE()[idx].sg_rgb_fg = -1; HL_TABLE()[idx].sg_rgb_fg = -1;
HL_TABLE()[idx].sg_rgb_bg = -1; HL_TABLE()[idx].sg_rgb_bg = -1;
free(HL_TABLE()[idx].sg_rgb_fg_name); xfree(HL_TABLE()[idx].sg_rgb_fg_name);
HL_TABLE()[idx].sg_rgb_fg_name = NULL; HL_TABLE()[idx].sg_rgb_fg_name = NULL;
free(HL_TABLE()[idx].sg_rgb_bg_name); xfree(HL_TABLE()[idx].sg_rgb_bg_name);
HL_TABLE()[idx].sg_rgb_bg_name = NULL; HL_TABLE()[idx].sg_rgb_bg_name = NULL;
/* Clear the script ID only when there is no link, since that is not /* Clear the script ID only when there is no link, since that is not
* cleared. */ * cleared. */
@ -6959,7 +6959,7 @@ int syn_namen2id(char_u *linep, int len)
{ {
char_u *name = vim_strnsave(linep, len); char_u *name = vim_strnsave(linep, len);
int id = syn_name2id(name); int id = syn_name2id(name);
free(name); xfree(name);
return id; return id;
} }
@ -6981,7 +6981,7 @@ int syn_check_group(char_u *pp, int len)
if (id == 0) /* doesn't exist yet */ if (id == 0) /* doesn't exist yet */
id = syn_add_group(name); id = syn_add_group(name);
else else
free(name); xfree(name);
return id; return id;
} }
@ -6998,7 +6998,7 @@ static int syn_add_group(char_u *name)
for (p = name; *p != NUL; ++p) { for (p = name; *p != NUL; ++p) {
if (!vim_isprintc(*p)) { if (!vim_isprintc(*p)) {
EMSG(_("E669: Unprintable character in group name")); EMSG(_("E669: Unprintable character in group name"));
free(name); xfree(name);
return 0; return 0;
} else if (!ASCII_ISALNUM(*p) && *p != '_') { } else if (!ASCII_ISALNUM(*p) && *p != '_') {
/* This is an error, but since there previously was no check only /* This is an error, but since there previously was no check only
@ -7019,7 +7019,7 @@ static int syn_add_group(char_u *name)
if (highlight_ga.ga_len >= MAX_HL_ID) { if (highlight_ga.ga_len >= MAX_HL_ID) {
EMSG(_("E849: Too many highlight and syntax groups")); EMSG(_("E849: Too many highlight and syntax groups"));
free(name); xfree(name);
return 0; return 0;
} }
@ -7039,8 +7039,8 @@ static int syn_add_group(char_u *name)
static void syn_unadd_group(void) static void syn_unadd_group(void)
{ {
--highlight_ga.ga_len; --highlight_ga.ga_len;
free(HL_TABLE()[highlight_ga.ga_len].sg_name); xfree(HL_TABLE()[highlight_ga.ga_len].sg_name);
free(HL_TABLE()[highlight_ga.ga_len].sg_name_u); xfree(HL_TABLE()[highlight_ga.ga_len].sg_name_u);
} }
/* /*

View File

@ -246,7 +246,7 @@ do_tag (
cur_match = ptag_entry.cur_match; cur_match = ptag_entry.cur_match;
cur_fnum = ptag_entry.cur_fnum; cur_fnum = ptag_entry.cur_fnum;
} else { } else {
free(ptag_entry.tagname); xfree(ptag_entry.tagname);
ptag_entry.tagname = vim_strsave(tag); ptag_entry.tagname = vim_strsave(tag);
} }
} else { } else {
@ -255,12 +255,12 @@ do_tag (
* stack entries above it. * stack entries above it.
*/ */
while (tagstackidx < tagstacklen) while (tagstackidx < tagstacklen)
free(tagstack[--tagstacklen].tagname); xfree(tagstack[--tagstacklen].tagname);
/* if the tagstack is full: remove oldest entry */ /* if the tagstack is full: remove oldest entry */
if (++tagstacklen > TAGSTACKSIZE) { if (++tagstacklen > TAGSTACKSIZE) {
tagstacklen = TAGSTACKSIZE; tagstacklen = TAGSTACKSIZE;
free(tagstack[0].tagname); xfree(tagstack[0].tagname);
for (i = 1; i < tagstacklen; ++i) for (i = 1; i < tagstacklen; ++i)
tagstack[i - 1] = tagstack[i]; tagstack[i - 1] = tagstack[i];
--tagstackidx; --tagstackidx;
@ -450,7 +450,7 @@ do_tag (
|| (cur_match >= num_matches && max_num_matches != MAXCOL) || (cur_match >= num_matches && max_num_matches != MAXCOL)
|| other_name) { || other_name) {
if (other_name) { if (other_name) {
free(tagmatchname); xfree(tagmatchname);
tagmatchname = vim_strsave(name); tagmatchname = vim_strsave(name);
} }
@ -569,7 +569,7 @@ do_tag (
* it and put "..." in the middle */ * it and put "..." in the middle */
p = tag_full_fname(&tagp); p = tag_full_fname(&tagp);
msg_puts_long_attr(p, hl_attr(HLF_D)); msg_puts_long_attr(p, hl_attr(HLF_D));
free(p); xfree(p);
if (msg_col > 0) if (msg_col > 0)
msg_putchar('\n'); msg_putchar('\n');
@ -709,7 +709,7 @@ do_tag (
/* Save the tag file name */ /* Save the tag file name */
p = tag_full_fname(&tagp); p = tag_full_fname(&tagp);
STRLCPY(fname, p, MAXPATHL + 1); STRLCPY(fname, p, MAXPATHL + 1);
free(p); xfree(p);
/* /*
* Get the line number or the search pattern used to locate * Get the line number or the search pattern used to locate
@ -804,8 +804,8 @@ do_tag (
set_errorlist(curwin, list, ' ', IObuff); set_errorlist(curwin, list, ' ', IObuff);
list_free(list, TRUE); list_free(list, TRUE);
free(fname); xfree(fname);
free(cmd); xfree(cmd);
cur_match = 0; /* Jump to the first tag */ cur_match = 0; /* Jump to the first tag */
} }
@ -941,7 +941,7 @@ end_do_tag:
*/ */
void tag_freematch(void) void tag_freematch(void)
{ {
free(tagmatchname); xfree(tagmatchname);
tagmatchname = NULL; tagmatchname = NULL;
} }
@ -983,7 +983,7 @@ void do_tags(exarg_T *eap)
msg_outtrans(IObuff); msg_outtrans(IObuff);
msg_outtrans_attr(name, tagstack[i].fmark.fnum == curbuf->b_fnum msg_outtrans_attr(name, tagstack[i].fmark.fnum == curbuf->b_fnum
? hl_attr(HLF_D) : 0); ? hl_attr(HLF_D) : 0);
free(name); xfree(name);
} }
ui_flush(); /* show one line at a time */ ui_flush(); /* show one line at a time */
} }
@ -1411,12 +1411,12 @@ line_read_in:
/* Copy or swap lbuf and conv_line. */ /* Copy or swap lbuf and conv_line. */
len = (int)STRLEN(conv_line) + 1; len = (int)STRLEN(conv_line) + 1;
if (len > lbuf_size) { if (len > lbuf_size) {
free(lbuf); xfree(lbuf);
lbuf = conv_line; lbuf = conv_line;
lbuf_size = len; lbuf_size = len;
} else { } else {
STRCPY(lbuf, conv_line); STRCPY(lbuf, conv_line);
free(conv_line); xfree(conv_line);
} }
} }
} }
@ -1873,7 +1873,7 @@ parse_line:
[ga_match[mtt].ga_len++] = mfp; [ga_match[mtt].ga_len++] = mfp;
++match_count; ++match_count;
} else } else
free(mfp); xfree(mfp);
} }
} }
} }
@ -1932,9 +1932,9 @@ parse_line:
} }
findtag_end: findtag_end:
free(lbuf); xfree(lbuf);
vim_regfree(orgpat.regmatch.regprog); vim_regfree(orgpat.regmatch.regprog);
free(tag_fname); xfree(tag_fname);
/* /*
* Move the matches from the ga_match[] arrays into one list of * Move the matches from the ga_match[] arrays into one list of
@ -1952,7 +1952,7 @@ findtag_end:
for (int i = 0; i < ga_match[mtt].ga_len; ++i) { for (int i = 0; i < ga_match[mtt].ga_len; ++i) {
mfp = ((struct match_found **)(ga_match[mtt].ga_data))[i]; mfp = ((struct match_found **)(ga_match[mtt].ga_data))[i];
if (matches == NULL) if (matches == NULL)
free(mfp); xfree(mfp);
else { else {
/* To avoid allocating memory again we turn the struct /* To avoid allocating memory again we turn the struct
* match_found into a string. For help the priority was not * match_found into a string. For help the priority was not
@ -1969,7 +1969,7 @@ findtag_end:
*num_matches = match_count; *num_matches = match_count;
curbuf->b_help = help_save; curbuf->b_help = help_save;
free(saved_pat); xfree(saved_pat);
return retval; return retval;
} }
@ -1993,7 +1993,7 @@ void free_tag_stuff(void)
tag_freematch(); tag_freematch();
if (ptag_entry.tagname) { if (ptag_entry.tagname) {
free(ptag_entry.tagname); xfree(ptag_entry.tagname);
ptag_entry.tagname = NULL; ptag_entry.tagname = NULL;
} }
} }
@ -2102,7 +2102,7 @@ get_tagfname (
} }
STRCPY(buf, fname); STRCPY(buf, fname);
free(fname); xfree(fname);
return OK; return OK;
} }
@ -2111,7 +2111,7 @@ get_tagfname (
*/ */
void tagname_free(tagname_T *tnp) void tagname_free(tagname_T *tnp)
{ {
free(tnp->tn_tags); xfree(tnp->tn_tags);
vim_findfile_cleanup(tnp->tn_search_ctx); vim_findfile_cleanup(tnp->tn_search_ctx);
tnp->tn_search_ctx = NULL; tnp->tn_search_ctx = NULL;
ga_clear_strings(&tag_fnames); ga_clear_strings(&tag_fnames);
@ -2362,7 +2362,7 @@ jumpto_tag (
&& !has_autocmd(EVENT_BUFREADCMD, fname, NULL) && !has_autocmd(EVENT_BUFREADCMD, fname, NULL)
) { ) {
retval = NOTAGFILE; retval = NOTAGFILE;
free(nofile_fname); xfree(nofile_fname);
nofile_fname = vim_strsave(fname); nofile_fname = vim_strsave(fname);
goto erret; goto erret;
} }
@ -2565,9 +2565,9 @@ erret:
g_do_tagpreview = 0; /* For next time */ g_do_tagpreview = 0; /* For next time */
if (tagp.fname_end != NULL) if (tagp.fname_end != NULL)
*tagp.fname_end = csave; *tagp.fname_end = csave;
free(pbuf); xfree(pbuf);
free(tofree_fname); xfree(tofree_fname);
free(full_fname); xfree(full_fname);
return retval; return retval;
} }
@ -2611,7 +2611,7 @@ static char_u *expand_tag_fname(char_u *fname, char_u *tag_fname, int expand)
} else } else
retval = vim_strsave(fname); retval = vim_strsave(fname);
free(expanded_fname); xfree(expanded_fname);
return retval; return retval;
} }
@ -2635,7 +2635,7 @@ static int test_for_current(char_u *fname, char_u *fname_end, char_u *tag_fname,
} }
fullname = expand_tag_fname(fname, tag_fname, TRUE); fullname = expand_tag_fname(fname, tag_fname, TRUE);
retval = (path_full_compare(fullname, buf_ffname, TRUE) & kEqualFiles); retval = (path_full_compare(fullname, buf_ffname, TRUE) & kEqualFiles);
free(fullname); xfree(fullname);
*fname_end = c; *fname_end = c;
} }
@ -2761,7 +2761,7 @@ add_tag_field (
} }
buf[len] = NUL; buf[len] = NUL;
retval = dict_add_nr_str(dict, field_name, 0L, buf); retval = dict_add_nr_str(dict, field_name, 0L, buf);
free(buf); xfree(buf);
return retval; return retval;
} }
@ -2804,7 +2804,7 @@ int get_tags(list_T *list, char_u *pat)
|| dict_add_nr_str(dict, "static", is_static, NULL) == FAIL) || dict_add_nr_str(dict, "static", is_static, NULL) == FAIL)
ret = FAIL; ret = FAIL;
free(full_fname); xfree(full_fname);
if (tp.command_end != NULL) { if (tp.command_end != NULL) {
for (p = tp.command_end + 3; for (p = tp.command_end + 3;
@ -2844,9 +2844,9 @@ int get_tags(list_T *list, char_u *pat)
} }
} }
free(matches[i]); xfree(matches[i]);
} }
free(matches); xfree(matches);
} }
return ret; return ret;
} }

View File

@ -77,7 +77,7 @@ void vim_deltempdir(void)
path_tail(NameBuff)[-1] = NUL; path_tail(NameBuff)[-1] = NUL;
os_rmdir((char *)NameBuff); os_rmdir((char *)NameBuff);
free(vim_tempdir); xfree(vim_tempdir);
vim_tempdir = NULL; vim_tempdir = NULL;
} }
} }
@ -109,7 +109,7 @@ static bool vim_settempdir(char_u *tempdir)
vim_FullName(tempdir, buf, MAXPATHL, false); vim_FullName(tempdir, buf, MAXPATHL, false);
add_pathsep(buf); add_pathsep(buf);
vim_tempdir = vim_strsave(buf); vim_tempdir = vim_strsave(buf);
free(buf); xfree(buf);
return true; return true;
} }

View File

@ -243,7 +243,7 @@ Terminal *terminal_open(TerminalOptions opts)
char *name = get_config_string(rv, var); char *name = get_config_string(rv, var);
if (name) { if (name) {
color_val = name_to_color((uint8_t *)name); color_val = name_to_color((uint8_t *)name);
free(name); xfree(name);
if (color_val != -1) { if (color_val != -1) {
rv->colors[i] = color_val; rv->colors[i] = color_val;
@ -424,11 +424,11 @@ void terminal_destroy(Terminal *term)
term->buf = NULL; term->buf = NULL;
pmap_del(ptr_t)(invalidated_terminals, term); pmap_del(ptr_t)(invalidated_terminals, term);
for (size_t i = 0 ; i < term->sb_current; i++) { for (size_t i = 0 ; i < term->sb_current; i++) {
free(term->sb_buffer[i]); xfree(term->sb_buffer[i]);
} }
free(term->sb_buffer); xfree(term->sb_buffer);
vterm_free(term->vt); vterm_free(term->vt);
free(term); xfree(term);
} }
void terminal_send(Terminal *term, char *data, size_t size) void terminal_send(Terminal *term, char *data, size_t size)
@ -603,7 +603,7 @@ static int term_sb_push(int cols, const VTermScreenCell *cells, void *data)
// Recycle old row if it's the right size // Recycle old row if it's the right size
sbrow = term->sb_buffer[term->sb_current - 1]; sbrow = term->sb_buffer[term->sb_current - 1];
} else { } else {
free(term->sb_buffer[term->sb_current - 1]); xfree(term->sb_buffer[term->sb_current - 1]);
} }
memmove(term->sb_buffer + 1, term->sb_buffer, memmove(term->sb_buffer + 1, term->sb_buffer,
@ -664,7 +664,7 @@ static int term_sb_pop(int cols, VTermScreenCell *cells, void *data)
cells[col].chars[0] = 0; cells[col].chars[0] = 0;
cells[col].width = 1; cells[col].width = 1;
} }
free(sbrow); xfree(sbrow);
pmap_put(ptr_t)(invalidated_terminals, term, NULL); pmap_put(ptr_t)(invalidated_terminals, term, NULL);
return 1; return 1;

View File

@ -296,5 +296,5 @@ static void term_input_destroy(TermInput *input)
uv_close((uv_handle_t *)&input->timer_handle, NULL); uv_close((uv_handle_t *)&input->timer_handle, NULL);
termkey_destroy(input->tk); termkey_destroy(input->tk);
event_poll(0); // Run once to remove references to input/timer handles event_poll(0); // Run once to remove references to input/timer handles
free(input); xfree(input);
} }

View File

@ -190,12 +190,12 @@ static void tui_stop(UI *ui)
if (uv_loop_close(data->write_loop)) { if (uv_loop_close(data->write_loop)) {
abort(); abort();
} }
free(data->write_loop); xfree(data->write_loop);
unibi_destroy(data->ut); unibi_destroy(data->ut);
destroy_screen(data); destroy_screen(data);
free(data); xfree(data);
ui_detach(ui); ui_detach(ui);
free(ui); xfree(ui);
} }
static void try_resize(Event ev) static void try_resize(Event ev)
@ -851,8 +851,8 @@ static void destroy_screen(TUIData *data)
{ {
if (data->screen) { if (data->screen) {
for (int i = 0; i < data->old_height; i++) { for (int i = 0; i < data->old_height; i++) {
free(data->screen[i]); xfree(data->screen[i]);
} }
free(data->screen); xfree(data->screen);
} }
} }

View File

@ -686,11 +686,11 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading)
(!reading || os_file_exists(undo_file_name))) { (!reading || os_file_exists(undo_file_name))) {
break; break;
} }
free(undo_file_name); xfree(undo_file_name);
undo_file_name = NULL; undo_file_name = NULL;
} }
free(munged_name); xfree(munged_name);
return undo_file_name; return undo_file_name;
} }
@ -710,7 +710,7 @@ static void u_free_uhp(u_header_T *uhp)
u_freeentry(uep, uep->ue_size); u_freeentry(uep, uep->ue_size);
uep = nuep; uep = nuep;
} }
free(uhp); xfree(uhp);
} }
/// Writes the header. /// Writes the header.
@ -823,7 +823,7 @@ static u_header_T *unserialize_uhp(bufinfo_T *bi, char_u *file_name)
uhp->uh_seq = undo_read_4c(bi); uhp->uh_seq = undo_read_4c(bi);
if (uhp->uh_seq <= 0) { if (uhp->uh_seq <= 0) {
corruption_error("uh_seq", file_name); corruption_error("uh_seq", file_name);
free(uhp); xfree(uhp);
return NULL; return NULL;
} }
unserialize_pos(bi, &uhp->uh_cursor); unserialize_pos(bi, &uhp->uh_cursor);
@ -1204,7 +1204,7 @@ write_error:
theend: theend:
if (file_name != name) if (file_name != name)
free(file_name); xfree(file_name);
} }
/// Loads the undo tree from an undo file. /// Loads the undo tree from an undo file.
@ -1470,7 +1470,7 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
curbuf->b_u_save_nr_cur = last_save_nr; curbuf->b_u_save_nr_cur = last_save_nr;
curbuf->b_u_synced = true; curbuf->b_u_synced = true;
free(uhp_table); xfree(uhp_table);
#ifdef U_DEBUG #ifdef U_DEBUG
for (int i = 0; i < num_head; i++) { for (int i = 0; i < num_head; i++) {
@ -1478,7 +1478,7 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
EMSGN("uhp_table entry %" PRId64 " not used, leaking memory", i); EMSGN("uhp_table entry %" PRId64 " not used, leaking memory", i);
} }
} }
free(uhp_table_used); xfree(uhp_table_used);
u_check(TRUE); u_check(TRUE);
#endif #endif
@ -1488,13 +1488,13 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
goto theend; goto theend;
error: error:
free(line_ptr); xfree(line_ptr);
if (uhp_table != NULL) { if (uhp_table != NULL) {
for (long i = 0; i < num_read_uhps; i++) for (long i = 0; i < num_read_uhps; i++)
if (uhp_table[i] != NULL) { if (uhp_table[i] != NULL) {
u_free_uhp(uhp_table[i]); u_free_uhp(uhp_table[i]);
} }
free(uhp_table); xfree(uhp_table);
} }
theend: theend:
@ -1502,7 +1502,7 @@ theend:
fclose(fp); fclose(fp);
} }
if (file_name != name) { if (file_name != name) {
free(file_name); xfree(file_name);
} }
} }
@ -1579,7 +1579,7 @@ static uint8_t *undo_read_string(bufinfo_T *bi, size_t len)
{ {
uint8_t *ptr = xmallocz(len); uint8_t *ptr = xmallocz(len);
if (len > 0 && !undo_read(bi, ptr, len)) { if (len > 0 && !undo_read(bi, ptr, len)) {
free(ptr); xfree(ptr);
return NULL; return NULL;
} }
return ptr; return ptr;
@ -2107,9 +2107,9 @@ static void u_undoredo(int undo)
ml_replace((linenr_T)1, uep->ue_array[i], TRUE); ml_replace((linenr_T)1, uep->ue_array[i], TRUE);
else else
ml_append(lnum, uep->ue_array[i], (colnr_T)0, FALSE); ml_append(lnum, uep->ue_array[i], (colnr_T)0, FALSE);
free(uep->ue_array[i]); xfree(uep->ue_array[i]);
} }
free((char_u *)uep->ue_array); xfree((char_u *)uep->ue_array);
} }
/* adjust marks */ /* adjust marks */
@ -2668,7 +2668,7 @@ u_freeentries (
#ifdef U_DEBUG #ifdef U_DEBUG
uhp->uh_magic = 0; uhp->uh_magic = 0;
#endif #endif
free((char_u *)uhp); xfree((char_u *)uhp);
--buf->b_u_numhead; --buf->b_u_numhead;
} }
@ -2678,12 +2678,12 @@ u_freeentries (
static void u_freeentry(u_entry_T *uep, long n) static void u_freeentry(u_entry_T *uep, long n)
{ {
while (n > 0) while (n > 0)
free(uep->ue_array[--n]); xfree(uep->ue_array[--n]);
free((char_u *)uep->ue_array); xfree((char_u *)uep->ue_array);
#ifdef U_DEBUG #ifdef U_DEBUG
uep->ue_magic = 0; uep->ue_magic = 0;
#endif #endif
free((char_u *)uep); xfree((char_u *)uep);
} }
/* /*
@ -2723,7 +2723,7 @@ void u_saveline(linenr_T lnum)
void u_clearline(void) void u_clearline(void)
{ {
if (curbuf->b_u_line_ptr != NULL) { if (curbuf->b_u_line_ptr != NULL) {
free(curbuf->b_u_line_ptr); xfree(curbuf->b_u_line_ptr);
curbuf->b_u_line_ptr = NULL; curbuf->b_u_line_ptr = NULL;
curbuf->b_u_line_lnum = 0; curbuf->b_u_line_lnum = 0;
} }
@ -2756,7 +2756,7 @@ void u_undoline(void)
oldp = u_save_line(curbuf->b_u_line_lnum); oldp = u_save_line(curbuf->b_u_line_lnum);
ml_replace(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr, TRUE); ml_replace(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr, TRUE);
changed_bytes(curbuf->b_u_line_lnum, 0); changed_bytes(curbuf->b_u_line_lnum, 0);
free(curbuf->b_u_line_ptr); xfree(curbuf->b_u_line_ptr);
curbuf->b_u_line_ptr = oldp; curbuf->b_u_line_ptr = oldp;
t = curbuf->b_u_line_colnr; t = curbuf->b_u_line_colnr;
@ -2777,7 +2777,7 @@ void u_blockfree(buf_T *buf)
u_freeheader(buf, buf->b_u_oldhead, NULL); u_freeheader(buf, buf->b_u_oldhead, NULL);
assert(buf->b_u_oldhead != previous_oldhead); assert(buf->b_u_oldhead != previous_oldhead);
} }
free(buf->b_u_line_ptr); xfree(buf->b_u_line_ptr);
} }
/* /*

View File

@ -401,7 +401,7 @@ wingotofile:
beginline(BL_SOL | BL_FIX); beginline(BL_SOL | BL_FIX);
} }
} }
free(ptr); xfree(ptr);
} }
break; break;
@ -2065,7 +2065,7 @@ win_free_mem (
/* Remove the window and its frame from the tree of frames. */ /* Remove the window and its frame from the tree of frames. */
frp = win->w_frame; frp = win->w_frame;
wp = winframe_remove(win, dirp, tp); wp = winframe_remove(win, dirp, tp);
free(frp); xfree(frp);
win_free(win, tp); win_free(win, tp);
/* When deleting the current window of another tab page select a new /* When deleting the current window of another tab page select a new
@ -2209,7 +2209,7 @@ winframe_remove (
if (frp2->fr_win != NULL) if (frp2->fr_win != NULL)
frp2->fr_win->w_frame = frp2->fr_parent; frp2->fr_win->w_frame = frp2->fr_parent;
frp = frp2->fr_parent; frp = frp2->fr_parent;
free(frp2); xfree(frp2);
frp2 = frp->fr_parent; frp2 = frp->fr_parent;
if (frp2 != NULL && frp2->fr_layout == frp->fr_layout) { if (frp2 != NULL && frp2->fr_layout == frp->fr_layout) {
@ -2230,7 +2230,7 @@ winframe_remove (
break; break;
} }
} }
free(frp); xfree(frp);
} }
} }
@ -2914,7 +2914,7 @@ void free_tabpage(tabpage_T *tp)
free(tp); xfree(tp);
} }
/* /*
@ -2934,7 +2934,7 @@ int win_new_tabpage(int after)
/* Remember the current windows in this Tab page. */ /* Remember the current windows in this Tab page. */
if (leave_tabpage(curbuf, TRUE) == FAIL) { if (leave_tabpage(curbuf, TRUE) == FAIL) {
free(newtp); xfree(newtp);
return FAIL; return FAIL;
} }
curtab = newtp; curtab = newtp;
@ -3528,7 +3528,7 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid, int tri
/* Window doesn't have a local directory and we are not in the global /* Window doesn't have a local directory and we are not in the global
* directory: Change to the global directory. */ * directory: Change to the global directory. */
ignored = os_chdir((char *)globaldir); ignored = os_chdir((char *)globaldir);
free(globaldir); xfree(globaldir);
globaldir = NULL; globaldir = NULL;
shorten_fnames(TRUE); shorten_fnames(TRUE);
} }
@ -3702,9 +3702,9 @@ win_free (
win_free_lsize(wp); win_free_lsize(wp);
for (i = 0; i < wp->w_tagstacklen; ++i) for (i = 0; i < wp->w_tagstacklen; ++i)
free(wp->w_tagstack[i].tagname); xfree(wp->w_tagstack[i].tagname);
free(wp->w_localdir); xfree(wp->w_localdir);
/* Remove the window from the b_wininfo lists, it may happen that the /* Remove the window from the b_wininfo lists, it may happen that the
* freed memory is re-used for another window. */ * freed memory is re-used for another window. */
@ -3721,7 +3721,7 @@ win_free (
qf_free_all(wp); qf_free_all(wp);
free(wp->w_p_cc_cols); xfree(wp->w_p_cc_cols);
if (wp != aucmd_win) if (wp != aucmd_win)
win_remove(wp, tp); win_remove(wp, tp);
@ -3729,7 +3729,7 @@ win_free (
wp->w_next = au_pending_free_win; wp->w_next = au_pending_free_win;
au_pending_free_win = wp; au_pending_free_win = wp;
} else { } else {
free(wp); xfree(wp);
} }
unblock_autocmds(); unblock_autocmds();
@ -3839,7 +3839,7 @@ void win_free_lsize(win_T *wp)
{ {
// TODO: why would wp be NULL here? // TODO: why would wp be NULL here?
if (wp != NULL) { if (wp != NULL) {
free(wp->w_lines); xfree(wp->w_lines);
wp->w_lines = NULL; wp->w_lines = NULL;
} }
} }
@ -5136,7 +5136,7 @@ static void clear_snapshot_rec(frame_T *fr)
if (fr != NULL) { if (fr != NULL) {
clear_snapshot_rec(fr->fr_next); clear_snapshot_rec(fr->fr_next);
clear_snapshot_rec(fr->fr_child); clear_snapshot_rec(fr->fr_child);
free(fr); xfree(fr);
} }
} }
@ -5472,7 +5472,7 @@ int match_add(win_T *wp, char_u *grp, char_u *pat, int prio, int id, list_T *pos
return id; return id;
fail: fail:
free(m); xfree(m);
return -1; return -1;
} }
@ -5507,7 +5507,7 @@ int match_delete(win_T *wp, int id, int perr)
else else
prev->next = cur->next; prev->next = cur->next;
vim_regfree(cur->match.regprog); vim_regfree(cur->match.regprog);
free(cur->pattern); xfree(cur->pattern);
if (cur->pos.toplnum != 0) { if (cur->pos.toplnum != 0) {
if (wp->w_buffer->b_mod_set) { if (wp->w_buffer->b_mod_set) {
if (wp->w_buffer->b_mod_top > cur->pos.toplnum) { if (wp->w_buffer->b_mod_top > cur->pos.toplnum) {
@ -5524,7 +5524,7 @@ int match_delete(win_T *wp, int id, int perr)
} }
rtype = VALID; rtype = VALID;
} }
free(cur); xfree(cur);
redraw_later(rtype); redraw_later(rtype);
return 0; return 0;
} }
@ -5539,8 +5539,8 @@ void clear_matches(win_T *wp)
while (wp->w_match_head != NULL) { while (wp->w_match_head != NULL) {
m = wp->w_match_head->next; m = wp->w_match_head->next;
vim_regfree(wp->w_match_head->match.regprog); vim_regfree(wp->w_match_head->match.regprog);
free(wp->w_match_head->pattern); xfree(wp->w_match_head->pattern);
free(wp->w_match_head); xfree(wp->w_match_head);
wp->w_match_head = m; wp->w_match_head = m;
} }
redraw_later(SOME_VALID); redraw_later(SOME_VALID);

View File

@ -13,6 +13,7 @@ set(DEPS_DOWNLOAD_DIR "${DEPS_BUILD_DIR}/downloads")
option(USE_BUNDLED "Use bundled dependencies." ON) option(USE_BUNDLED "Use bundled dependencies." ON)
option(USE_BUNDLED_JEMALLOC "Use the bundled jemalloc." ${USE_BUNDLED})
option(USE_BUNDLED_UNIBILIUM "Use the bundled unibilium." ${USE_BUNDLED}) option(USE_BUNDLED_UNIBILIUM "Use the bundled unibilium." ${USE_BUNDLED})
option(USE_BUNDLED_LIBTERMKEY "Use the bundled libtermkey." ${USE_BUNDLED}) option(USE_BUNDLED_LIBTERMKEY "Use the bundled libtermkey." ${USE_BUNDLED})
option(USE_BUNDLED_LIBVTERM "Use the bundled libvterm." ${USE_BUNDLED}) option(USE_BUNDLED_LIBVTERM "Use the bundled libvterm." ${USE_BUNDLED})
@ -73,6 +74,8 @@ set(LIBTERMKEY_SHA256 21846369081e6c9a0b615f4b3889c4cb809321c5ccc6e6c1640eb138f1
set(LIBVTERM_URL https://github.com/neovim/libvterm/archive/1b745d29d45623aa8d22a7b9288c7b0e331c7088.tar.gz) set(LIBVTERM_URL https://github.com/neovim/libvterm/archive/1b745d29d45623aa8d22a7b9288c7b0e331c7088.tar.gz)
set(LIBVTERM_SHA256 3fc75908256c0d158d6c2a32d39f34e86bfd26364f5404b7d9c03bb70cdc3611) set(LIBVTERM_SHA256 3fc75908256c0d158d6c2a32d39f34e86bfd26364f5404b7d9c03bb70cdc3611)
set(JEMALLOC_URL https://github.com/jemalloc/jemalloc/archive/3.6.0.tar.gz)
set(JEMALLOC_SHA256 68175f729423305dc8573cb093025a8db525e1956583c7c5924416a9abaaacb6)
if(USE_BUNDLED_UNIBILIUM) if(USE_BUNDLED_UNIBILIUM)
include(BuildUnibilium) include(BuildUnibilium)
@ -102,6 +105,10 @@ if(USE_BUNDLED_LUAROCKS)
include(BuildLuarocks) include(BuildLuarocks)
endif() endif()
if(USE_BUNDLED_JEMALLOC)
include(BuildJeMalloc)
endif()
add_custom_target(third-party ALL add_custom_target(third-party ALL
COMMAND ${CMAKE_COMMAND} -E touch .third-party COMMAND ${CMAKE_COMMAND} -E touch .third-party
DEPENDS ${THIRD_PARTY_DEPS}) DEPENDS ${THIRD_PARTY_DEPS})

19
third-party/cmake/BuildJeMalloc.cmake vendored Normal file
View File

@ -0,0 +1,19 @@
ExternalProject_Add(jemalloc
PREFIX ${DEPS_BUILD_DIR}
URL ${JEMALLOC_URL}
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/jemalloc
DOWNLOAD_COMMAND ${CMAKE_COMMAND}
-DPREFIX=${DEPS_BUILD_DIR}
-DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/jemalloc
-DURL=${JEMALLOC_URL}
-DEXPECTED_SHA256=${JEMALLOC_SHA256}
-DTARGET=jemalloc
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND sh ${DEPS_BUILD_DIR}/src/jemalloc/autogen.sh &&
${DEPS_BUILD_DIR}/src/jemalloc/configure --with-jemalloc-prefix=je_
--enable-cc-silence CC=${DEPS_C_COMPILER} --prefix=${DEPS_INSTALL_DIR}
BUILD_COMMAND ""
INSTALL_COMMAND ${MAKE_PRG} install_include install_lib)
list(APPEND THIRD_PARTY_DEPS jemalloc)