diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2019-05-25 14:49:43 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-25 14:49:43 +0200 | 
| commit | 2f023f40b275a904c96d5b287e9e9abe6df1aec7 (patch) | |
| tree | 36f2b5bec81f7144c5bd3787f33959bd60c59e0e /src/nvim/memory.h | |
| parent | 4769deb36a54c3b2a4a2d2addb2937c1aa7dd629 (diff) | |
| parent | eddd1bff3e7bf8df7405f6b0bfd01a5bb8ba20a9 (diff) | |
| download | rneovim-2f023f40b275a904c96d5b287e9e9abe6df1aec7.tar.gz rneovim-2f023f40b275a904c96d5b287e9e9abe6df1aec7.tar.bz2 rneovim-2f023f40b275a904c96d5b287e9e9abe6df1aec7.zip | |
Merge #10046 from justinmk/xfree
refactor: introduce XFREE_CLEAR()
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 | 
