mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 10:37:22 +00:00
helper: add free_n method to handle clearing pointers
free_n() will free the memory and clear the pointer, which will reduce the probability a developer will forget to clear the pointer after freeing. Resolves: #79 Signed-off-by: Patrick Venture <venture@google.com>
This commit is contained in:
parent
34fc86bd75
commit
8b6d127bb1
@ -119,6 +119,17 @@ uint16_t ipmi_get_oem_id(struct ipmi_intf *intf);
|
||||
|
||||
#define IS_SET(v, b) ((v) & (1 << (b)))
|
||||
|
||||
/**
|
||||
* Free the memory and clear the pointer.
|
||||
* @param[in] ptr - a pointer to your pointer to free.
|
||||
*/
|
||||
static inline void free_n(void **ptr) {
|
||||
if (ptr && *ptr) {
|
||||
free(*ptr);
|
||||
*ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* le16toh(), hto16le(), et. al. don't exist for Windows or Apple */
|
||||
/* For portability, let's simply define our own versions here */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user