42 lines
1.2 KiB
Diff
42 lines
1.2 KiB
Diff
From 8b6d127bb14b9ad7ef28da1fc5f8c965df2123cd Mon Sep 17 00:00:00 2001
|
|
From: Patrick Venture <venture@google.com>
|
|
Date: Wed, 5 Dec 2018 08:55:59 -0800
|
|
Subject: [PATCH 093/119] 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>
|
|
---
|
|
include/ipmitool/helper.h | 11 +++++++++++
|
|
1 file changed, 11 insertions(+)
|
|
|
|
diff --git a/include/ipmitool/helper.h b/include/ipmitool/helper.h
|
|
index c53736f..c03c931 100644
|
|
--- a/include/ipmitool/helper.h
|
|
+++ b/include/ipmitool/helper.h
|
|
@@ -111,6 +111,17 @@ FILE * ipmi_open_file(const char * file, int rw);
|
|
void ipmi_start_daemon(struct ipmi_intf *intf);
|
|
uint16_t ipmi_get_oem_id(struct ipmi_intf *intf);
|
|
|
|
+/**
|
|
+ * 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;
|
|
+ }
|
|
+}
|
|
+
|
|
#define ipmi_open_file_read(file) ipmi_open_file(file, 0)
|
|
#define ipmi_open_file_write(file) ipmi_open_file(file, 1)
|
|
|
|
--
|
|
2.19.1
|
|
|