42 lines
1.3 KiB
Diff
42 lines
1.3 KiB
Diff
|
|
From cac906a942f41b9b8515b10877d3e0b23ef548a9 Mon Sep 17 00:00:00 2001
|
||
|
|
From: wuguanghao <wuguanghao3@huawei.com>
|
||
|
|
Date: Wed, 30 Jun 2021 16:27:13 +0800
|
||
|
|
Subject: [PATCH] profile_create_node: set magic before strdup(name) to avoid
|
||
|
|
memory leak
|
||
|
|
|
||
|
|
If new->magic != PROF_MAGIC_NODE, profile_free_node() don't free node.
|
||
|
|
This will cause the node to be unable to be released correctly and
|
||
|
|
a memory leak will occur.
|
||
|
|
|
||
|
|
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
|
||
|
|
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
|
||
|
|
Reviewed-by: Wu Bo <wubo40@huawei.com>
|
||
|
|
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
||
|
|
---
|
||
|
|
lib/support/profile.c | 2 +-
|
||
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
||
|
|
|
||
|
|
diff --git a/lib/support/profile.c b/lib/support/profile.c
|
||
|
|
index 585ed595..f54739e7 100644
|
||
|
|
--- a/lib/support/profile.c
|
||
|
|
+++ b/lib/support/profile.c
|
||
|
|
@@ -1093,6 +1093,7 @@ errcode_t profile_create_node(const char *name, const char *value,
|
||
|
|
if (!new)
|
||
|
|
return ENOMEM;
|
||
|
|
memset(new, 0, sizeof(struct profile_node));
|
||
|
|
+ new->magic = PROF_MAGIC_NODE;
|
||
|
|
new->name = strdup(name);
|
||
|
|
if (new->name == 0) {
|
||
|
|
profile_free_node(new);
|
||
|
|
@@ -1105,7 +1106,6 @@ errcode_t profile_create_node(const char *name, const char *value,
|
||
|
|
return ENOMEM;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
- new->magic = PROF_MAGIC_NODE;
|
||
|
|
|
||
|
|
*ret_node = new;
|
||
|
|
return 0;
|
||
|
|
--
|
||
|
|
2.25.1
|
||
|
|
|