Commit 235a1eb
of: unittest: Fix memory leak in unittest_data_add()
In unittest_data_add(), if of_resolve_phandles() fails, the allocated
unittest_data is not freed, leading to a memory leak.
Fix this by using scope-based cleanup helper __free(kfree) for automatic
resource cleanup. This ensures unittest_data is automatically freed when
it goes out of scope in error paths.
For the success path, use retain_and_null_ptr() to transfer ownership
of the memory to the device tree and prevent double freeing.
Fixes: 2eb46da ("of/selftest: Use the resolver to fixup phandles")
Suggested-by: Rob Herring <robh@kernel.org>
Co-developed-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Link: https://patch.msgid.link/20251231114915.234638-1-zilin@seu.edu.cn
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>1 parent 4f4f6b4 commit 235a1eb
1 file changed
Lines changed: 3 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1985 | 1985 | | |
1986 | 1986 | | |
1987 | 1987 | | |
1988 | | - | |
1989 | 1988 | | |
1990 | 1989 | | |
1991 | 1990 | | |
| |||
2004 | 2003 | | |
2005 | 2004 | | |
2006 | 2005 | | |
2007 | | - | |
| 2006 | + | |
2008 | 2007 | | |
2009 | 2008 | | |
2010 | 2009 | | |
| |||
2014 | 2013 | | |
2015 | 2014 | | |
2016 | 2015 | | |
2017 | | - | |
2018 | 2016 | | |
2019 | 2017 | | |
2020 | 2018 | | |
2021 | 2019 | | |
2022 | | - | |
2023 | 2020 | | |
2024 | 2021 | | |
2025 | 2022 | | |
| |||
2038 | 2035 | | |
2039 | 2036 | | |
2040 | 2037 | | |
2041 | | - | |
2042 | 2038 | | |
2043 | 2039 | | |
2044 | 2040 | | |
| |||
2059 | 2055 | | |
2060 | 2056 | | |
2061 | 2057 | | |
| 2058 | + | |
| 2059 | + | |
2062 | 2060 | | |
2063 | 2061 | | |
2064 | 2062 | | |
| |||
0 commit comments