代码拉取完成,页面将自动刷新
From 8b6d127bb14b9ad7ef28da1fc5f8c965df2123cd Mon Sep 17 00:00:00 2001
From: Patrick Venture <[email protected]>
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 <[email protected]>
---
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。