[PATCH] scripts/dtc: Fix memory leak in check_msg()

Stanislav Goriainov posted 1 patch 3 years, 8 months ago
scripts/dtc/checks.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] scripts/dtc: Fix memory leak in check_msg()
Posted by Stanislav Goriainov 3 years, 8 months ago
When the function check_msg() is called, memory for str is allocated
via xasprintf() and xasprintf_append() (as well as for file_str),
but is not freed anywhere later (although file_str is).

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: c2e7075ca830 ("scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d145")
Signed-off-by: Stanislav Goriainov <goriainov@ispras.ru>
---
 scripts/dtc/checks.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/dtc/checks.c b/scripts/dtc/checks.c
index 781ba1129a8e..92ffc8de6a52 100644
--- a/scripts/dtc/checks.c
+++ b/scripts/dtc/checks.c
@@ -114,6 +114,7 @@ static inline void  PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti,
 	}
 
 	fputs(str, stderr);
+	free(str);
 }
 
 #define FAIL(c, dti, node, ...)						\
-- 2.34.1
Re: [PATCH] scripts/dtc: Fix memory leak in check_msg()
Posted by Rob Herring 3 years, 8 months ago
On Mon, Jul 25, 2022 at 10:00 AM Stanislav Goriainov
<goriainov@ispras.ru> wrote:
>
> When the function check_msg() is called, memory for str is allocated
> via xasprintf() and xasprintf_append() (as well as for file_str),
> but is not freed anywhere later (although file_str is).
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: c2e7075ca830 ("scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d145")

scripts/dtc/ is sync'ed periodically with upstream dtc. We don't take
patches against it. You must submit this to upstream dtc.

> Signed-off-by: Stanislav Goriainov <goriainov@ispras.ru>
> ---
>  scripts/dtc/checks.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/scripts/dtc/checks.c b/scripts/dtc/checks.c
> index 781ba1129a8e..92ffc8de6a52 100644
> --- a/scripts/dtc/checks.c
> +++ b/scripts/dtc/checks.c
> @@ -114,6 +114,7 @@ static inline void  PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti,
>         }
>
>         fputs(str, stderr);
> +       free(str);
>  }
>
>  #define FAIL(c, dti, node, ...)                                                \
> -- 2.34.1
>