diff mbox series

selftests: futex: Fix missing free in main

Message ID 20240904025559.7356-1-zhangjiao2@cmss.chinamobile.com (mailing list archive)
State New
Headers show
Series selftests: futex: Fix missing free in main | expand

Commit Message

zhangjiao2 Sept. 4, 2024, 2:55 a.m. UTC
From: zhang jiao <zhangjiao2@cmss.chinamobile.com>

Free string allocated by asprintf().

Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
---
 tools/testing/selftests/futex/functional/futex_requeue_pi.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Shuah Khan Sept. 4, 2024, 4:57 p.m. UTC | #1
On 9/3/24 20:55, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> 
> Free string allocated by asprintf().

How did you find this problem? Include the details in
the change log - The tool and output from the tool.

> 
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> ---
>   tools/testing/selftests/futex/functional/futex_requeue_pi.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi.c b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
> index 215c6cb539b4..fb2dab46087f 100644
> --- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c
> +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
> @@ -416,5 +416,8 @@ int main(int argc, char *argv[])
>   	ret = unit_test(broadcast, locked, owner, timeout_ns);
>   
>   	print_result(test_name, ret);
> +	if (strlen(test_name) > strlen(TEST_NAME))
> +		free(test_name);

Why not set a flag to determine if test_name needs freeing
instead of calling strlen() twice?

> +
>   	return ret;
>   }

thanks,
-- Shuah
diff mbox series

Patch

diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi.c b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
index 215c6cb539b4..fb2dab46087f 100644
--- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c
+++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
@@ -416,5 +416,8 @@  int main(int argc, char *argv[])
 	ret = unit_test(broadcast, locked, owner, timeout_ns);
 
 	print_result(test_name, ret);
+	if (strlen(test_name) > strlen(TEST_NAME))
+		free(test_name);
+
 	return ret;
 }