diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-05-22 00:10:35 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-05-25 10:01:17 +0200 |
commit | a9d7ec4587d8eb20f12ebecc427ad818fb0e4971 (patch) | |
tree | 4a3ec8787e9dae501ea2c1430c13c174f289ac4b /src/nvim/lib/kvec.h | |
parent | 4769deb36a54c3b2a4a2d2addb2937c1aa7dd629 (diff) | |
download | rneovim-a9d7ec4587d8eb20f12ebecc427ad818fb0e4971.tar.gz rneovim-a9d7ec4587d8eb20f12ebecc427ad818fb0e4971.tar.bz2 rneovim-a9d7ec4587d8eb20f12ebecc427ad818fb0e4971.zip |
refactor: introduce XFREE_CLEAR()
Unfortunately we cannot indiscriminately replace xfree() with
XFREE_CLEAR(), because comparing pointers after freeing them is a common
pattern. Example in `tv_list_remove_items()`:
xfree(li);
if (li == item2) {
break;
}
Instead we can do it selectively/explicitly.
ref #1375
Diffstat (limited to 'src/nvim/lib/kvec.h')
-rw-r--r-- | src/nvim/lib/kvec.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/nvim/lib/kvec.h b/src/nvim/lib/kvec.h index 93b2f053bc..e668b10bb9 100644 --- a/src/nvim/lib/kvec.h +++ b/src/nvim/lib/kvec.h @@ -58,7 +58,7 @@ } #define kv_init(v) ((v).size = (v).capacity = 0, (v).items = 0) -#define kv_destroy(v) xfree((v).items) +#define kv_destroy(v) XFREE_CLEAR((v).items) #define kv_A(v, i) ((v).items[(i)]) #define kv_pop(v) ((v).items[--(v).size]) #define kv_size(v) ((v).size) @@ -138,7 +138,7 @@ static inline void *_memcpy_free(void *const restrict dest, FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET FUNC_ATTR_ALWAYS_INLINE { memcpy(dest, src, size); - xfree(src); + XFREE_CLEAR(src); return dest; } @@ -201,7 +201,7 @@ static inline void *_memcpy_free(void *const restrict dest, #define kvi_destroy(v) \ do { \ if ((v).items != (v).init_array) { \ - xfree((v).items); \ + XFREE_CLEAR((v).items); \ } \ } while (0) |