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/memory.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/memory.h')
-rw-r--r-- | src/nvim/memory.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/nvim/memory.h b/src/nvim/memory.h index 250ac3e08f..5b39d002c9 100644 --- a/src/nvim/memory.h +++ b/src/nvim/memory.h @@ -40,4 +40,15 @@ extern bool entered_free_all_mem; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "memory.h.generated.h" #endif + +#define XFREE_CLEAR(ptr) \ + do { \ + /* Take the address to avoid double evaluation. #1375 */ \ + void **ptr_ = (void **)&(ptr); \ + xfree(*ptr_); \ + /* coverity[dead-store] */ \ + *ptr_ = NULL; \ + (void)(*ptr_); \ + } while (0) + #endif // NVIM_MEMORY_H |