diff options
author | wuguanghao <wuguanghao3@huawei.com> | 2021-06-30 16:27:13 +0800 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2021-07-15 23:17:46 -0400 |
commit | cac906a942f41b9b8515b10877d3e0b23ef548a9 (patch) | |
tree | 9458eb4e6c0ea1b5e78b1b67cb4ff5ab82b13495 | |
parent | 657715deb85ce5cdea7bc2cc11dde2058d73f4c9 (diff) | |
download | e2fsprogs-cac906a942f41b9b8515b10877d3e0b23ef548a9.tar.gz |
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>
-rw-r--r-- | lib/support/profile.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/support/profile.c b/lib/support/profile.c index 585ed595d..f54739e7b 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; |