9 Star 0 Fork 5

src-openEuler/secDetector

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Backport-bug-fix-memory-leak-in-sc-analyze-unit.patch 3.28 KB
一键复制 编辑 原始数据 按行查看 历史
hurricane618 提交于 2023-12-21 12:53 . backport patchs to fix memory leak
From 2ff0256c1ca0bfb1e119fc419d2a9c3e7a48fc22 Mon Sep 17 00:00:00 2001
From: yieux <yangxy79315@sina.com>
Date: Wed, 20 Dec 2023 15:31:22 +0800
Subject: [PATCH] bug fix memory leak in sc analyze unit
---
.../analyze_unit/secDetector_save_check.c | 24 +++++++++++++------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/kerneldriver/core/analyze_unit/secDetector_save_check.c b/kerneldriver/core/analyze_unit/secDetector_save_check.c
index 4a5f689..788de3e 100644
--- a/kerneldriver/core/analyze_unit/secDetector_save_check.c
+++ b/kerneldriver/core/analyze_unit/secDetector_save_check.c
@@ -38,6 +38,11 @@ static int init_analyze_status_data_sc(analyze_status_t *analyze_status_data, in
return 0;
}
analyze_status_data->sc_data.data = kmalloc(sizeof(unsigned long long) * len, GFP_KERNEL);
+ if (analyze_status_data->sc_data.data == NULL) {
+ pr_err("kmalloc failed");
+ return -ENOMEM;
+ }
+ analyze_status_data->sc_data.data_type = ANALYZE_STATUS_SAVE_CHECK;
analyze_status_data->sc_data.len = len;
return 0;
}
@@ -51,6 +56,7 @@ void free_analyze_status_data_sc(analyze_status_t *analyze_status_data)
static int analyze_save_check_init(struct list_head *collect_data_list, analyze_status_t *analyze_status_data, response_data_t *response_data)
{
+ int ret = 0;
int data_index = 0;
struct collect_data *cd;
list_for_each_entry(cd, collect_data_list, list) {
@@ -58,7 +64,9 @@ static int analyze_save_check_init(struct list_head *collect_data_list, analyze_
continue;
data_index++;
}
- init_analyze_status_data_sc(analyze_status_data, data_index);
+ ret = init_analyze_status_data_sc(analyze_status_data, data_index);
+ if (ret < 0)
+ return ret;
data_index = 0;
list_for_each_entry(cd, collect_data_list, list) {
@@ -89,7 +97,7 @@ static int analyze_save_check_normal(struct list_head *collect_data_list, analyz
unsigned long long measure_value;
struct collect_data *cd;
char *timestamp = NULL;
- int timestamp_len;
+ int timestamp_len = 0;
char **response_arrays;
int response_array_index = 0;
char int_str[MAX_DIGITS];
@@ -124,7 +132,7 @@ static int analyze_save_check_normal(struct list_head *collect_data_list, analyz
break;
}
if (measure_value != analyze_status_data->sc_data.data[data_index]) {
- pr_warn("[save_check]%s: original: %llu; now: %llu.!\n",
+ pr_debug("[save_check]%s: original: %llu; now: %llu.!\n",
cd->name, analyze_status_data->sc_data.data[data_index], measure_value);
response_arrays[response_array_index] = kzalloc(strlen(cd->name) + REPORT_MORE_CHAR_LEN, GFP_KERNEL);
if (response_arrays[response_array_index] == NULL) {
@@ -162,15 +170,17 @@ static int analyze_save_check_normal(struct list_head *collect_data_list, analyz
ret = -ENOMEM;
goto end;
}
- if (timestamp_len > 0) {
- strncat(response_data->report_data.text, timestamp, timestamp_len);
- kfree(timestamp);
- }
+
for (i = 0; i < response_array_index; i++)
strncat(response_data->report_data.text, response_arrays[i], strlen(response_arrays[i]));
strcat(response_data->report_data.text, "\n");
}
+
end:
+ if (timestamp_len > 0) {
+ strncat(response_data->report_data.text, timestamp, timestamp_len);
+ kfree(timestamp);
+}
for (i = 0; i < response_array_index; i++)
kfree(response_arrays[i]);
kfree(response_arrays);
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/secDetector.git
git@gitee.com:src-openeuler/secDetector.git
src-openeuler
secDetector
secDetector
master

搜索帮助