* [PATCH v3] selftests: futex: Fix missing free in main
@ 2024-09-06 2:19 zhangjiao2
2024-09-06 14:17 ` Thomas Gleixner
0 siblings, 1 reply; 2+ messages in thread
From: zhangjiao2 @ 2024-09-06 2:19 UTC (permalink / raw)
To: skhan; +Cc: linux-kernel, linux-kselftest, mingo, shuah, tglx, zhang jiao
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>
---
v2->v3:
Use a bool flag to determine if test_name needs free.
tools/testing/selftests/futex/functional/futex_requeue_pi.c | 5 +++++
1 file changed, 5 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..a103c69c0a3b 100644
--- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c
+++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <signal.h>
#include <string.h>
+#include <stdbool.h>
#include "atomic.h"
#include "futextest.h"
#include "logging.h"
@@ -362,6 +363,7 @@ int main(int argc, char *argv[])
{
char *test_name;
int c, ret;
+ bool is_static = false;
while ((c = getopt(argc, argv, "bchlot:v:")) != -1) {
switch (c) {
@@ -404,6 +406,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) {
+ is_static = true;
ksft_print_msg("Failed to generate test name\n");
test_name = TEST_NAME;
}
@@ -416,5 +419,7 @@ int main(int argc, char *argv[])
ret = unit_test(broadcast, locked, owner, timeout_ns);
print_result(test_name, ret);
+ if (!is_static)
+ free(test_name);
return ret;
}
--
2.33.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v3] selftests: futex: Fix missing free in main
2024-09-06 2:19 [PATCH v3] selftests: futex: Fix missing free in main zhangjiao2
@ 2024-09-06 14:17 ` Thomas Gleixner
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2024-09-06 14:17 UTC (permalink / raw)
To: zhangjiao2, skhan; +Cc: linux-kernel, linux-kselftest, mingo, shuah, zhang jiao
On Fri, Sep 06 2024 at 10:19, zhangjiao2@cmss.chinamobile.com wrote:
> @@ -362,6 +363,7 @@ int main(int argc, char *argv[])
> {
> char *test_name;
> int c, ret;
> + bool is_static = false;
what means is_static? It's not connected to test_name in any way and
please use reverse fir tree variable ordering
https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#variable-declarations
So either use a variable name which makes it clear that it is related to
test_name (something obvious like: name_allocated) or do
char *test_name, *default_name = TEST_NAME;
and do test_name = default_name; in the error path and then check for
(test_name != default_name)
Whatever you pick will be better than the non-obvious is_static.
Thanks,
tglx
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-09-06 14:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-06 2:19 [PATCH v3] selftests: futex: Fix missing free in main zhangjiao2
2024-09-06 14:17 ` Thomas Gleixner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox