mirror of
https://github.com/neovim/neovim.git
synced 2025-10-03 00:18:33 +00:00
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
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user