10 Star 0 Fork 12

src-openEuler/ipmitool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
helper-add-free_n-method-to-handle-clearing-pointers.patch 1.18 KB
一键复制 编辑 原始数据 按行查看 历史
hexiaowen 提交于 2019-09-30 10:53 . Package init
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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/ipmitool.git
[email protected]:src-openeuler/ipmitool.git
src-openeuler
ipmitool
ipmitool
master

搜索帮助