diff mbox series

[v2] selftests: futex: Fix missing free in main

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

Commit Message

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

By readind the code, I found there is no free() after asprintf().
Just free it.

Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
---
v1->v2:
	Set a flag to determine if test_name needs free.
	
 tools/testing/selftests/futex/functional/futex_requeue_pi.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Shuah Khan Sept. 5, 2024, 8:08 p.m. UTC | #1
On 9/4/24 20:01, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> 
> By readind the code, I found there is no free() after asprintf().
> Just free it.
> 
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> ---
> v1->v2:
> 	Set a flag to determine if test_name needs free.
> 	
>   tools/testing/selftests/futex/functional/futex_requeue_pi.c | 4 ++++
>   1 file changed, 4 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..d78bb5112fce 100644
> --- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c
> +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
> @@ -362,6 +362,7 @@ int main(int argc, char *argv[])
>   {
>   	char *test_name;
>   	int c, ret;
> +	int need_f = 1;

This can be a bool which - better to set it to false as a initial
value.

>   
>   	while ((c = getopt(argc, argv, "bchlot:v:")) != -1) {
>   		switch (c) {
> @@ -404,6 +405,7 @@ int main(int argc, char *argv[])
>   		       "%s broadcast=%d locked=%d owner=%d timeout=%ldns",
>   		       TEST_NAME, broadcast, locked, owner, timeout_ns);
>   	if (ret < 0) {
> +		need_f = 0;

You would set it to TRUE here.

>   		ksft_print_msg("Failed to generate test name\n");
>   		test_name = TEST_NAME;
>   	}
> @@ -416,5 +418,7 @@ int main(int argc, char *argv[])
>   	ret = unit_test(broadcast, locked, owner, timeout_ns);
>   
>   	print_result(test_name, ret);
> +	if (need_f)

Check against TRUE

> +		free(test_name);
>   	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..d78bb5112fce 100644
--- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c
+++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
@@ -362,6 +362,7 @@  int main(int argc, char *argv[])
 {
 	char *test_name;
 	int c, ret;
+	int need_f = 1;
 
 	while ((c = getopt(argc, argv, "bchlot:v:")) != -1) {
 		switch (c) {
@@ -404,6 +405,7 @@  int main(int argc, char *argv[])
 		       "%s broadcast=%d locked=%d owner=%d timeout=%ldns",
 		       TEST_NAME, broadcast, locked, owner, timeout_ns);
 	if (ret < 0) {
+		need_f = 0;
 		ksft_print_msg("Failed to generate test name\n");
 		test_name = TEST_NAME;
 	}
@@ -416,5 +418,7 @@  int main(int argc, char *argv[])
 	ret = unit_test(broadcast, locked, owner, timeout_ns);
 
 	print_result(test_name, ret);
+	if (need_f)
+		free(test_name);
 	return ret;
 }