* [PATCH] selftests/riscv: ptrace: Fix memory leak of regset_data in vector tests
@ 2026-07-10 8:34 Wang Yan
2026-07-10 10:16 ` Sergey Matyukevich
2026-07-10 15:38 ` Paul Walmsley
0 siblings, 2 replies; 3+ messages in thread
From: Wang Yan @ 2026-07-10 8:34 UTC (permalink / raw)
To: shuah, pjw, palmer, aou, alex
Cc: geomatsi, andybnac, andrew.jones, wangyan01, thecharlesjenkins,
linux-kselftest, linux-riscv, linux-kernel
The regset_data buffer allocated with calloc() in the parent process
of several vector ptrace tests is never freed before returning,
causing memory leaks in:
- ptrace_v_not_enabled
- ptrace_v_early_debug
- ptrace_v_syscall_clobbering
- v_csr_invalid/ptrace_v_invalid_values
- v_csr_valid/ptrace_v_valid_values
Add free(regset_data) before kill(pid, SIGKILL) to release the
allocated buffer.
Signed-off-by: Wang Yan <wangyan01@kylinos.cn>
---
.../testing/selftests/riscv/vector/validate_v_ptrace.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/riscv/vector/validate_v_ptrace.c b/tools/testing/selftests/riscv/vector/validate_v_ptrace.c
index b038e2175c80..a388b7963d47 100644
--- a/tools/testing/selftests/riscv/vector/validate_v_ptrace.c
+++ b/tools/testing/selftests/riscv/vector/validate_v_ptrace.c
@@ -75,7 +75,7 @@ TEST(ptrace_v_not_enabled)
ASSERT_EQ(-1, ret);
/* cleanup */
-
+ free(regset_data);
ASSERT_EQ(0, kill(pid, SIGKILL));
}
}
@@ -207,7 +207,7 @@ TEST(ptrace_v_early_debug)
EXPECT_EQ(vl_csr, regset_data->vl);
/* cleanup */
-
+ free(regset_data);
ASSERT_EQ(0, kill(pid, SIGKILL));
}
}
@@ -331,7 +331,7 @@ TEST(ptrace_v_syscall_clobbering)
EXPECT_EQ(0UL, regset_data->vl);
/* cleanup */
-
+ free(regset_data);
ASSERT_EQ(0, kill(pid, SIGKILL));
}
}
@@ -649,7 +649,7 @@ TEST_F(v_csr_invalid, ptrace_v_invalid_values)
ASSERT_EQ(ret, -1);
/* cleanup */
-
+ free(regset_data);
ASSERT_EQ(0, kill(pid, SIGKILL));
}
}
@@ -911,7 +911,7 @@ TEST_F(v_csr_valid, ptrace_v_valid_values)
EXPECT_EQ(regset_data->vlenb, vlenb);
/* cleanup */
-
+ free(regset_data);
ASSERT_EQ(0, kill(pid, SIGKILL));
}
}
--
2.25.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/riscv: ptrace: Fix memory leak of regset_data in vector tests
2026-07-10 8:34 [PATCH] selftests/riscv: ptrace: Fix memory leak of regset_data in vector tests Wang Yan
@ 2026-07-10 10:16 ` Sergey Matyukevich
2026-07-10 15:38 ` Paul Walmsley
1 sibling, 0 replies; 3+ messages in thread
From: Sergey Matyukevich @ 2026-07-10 10:16 UTC (permalink / raw)
To: Wang Yan
Cc: shuah, pjw, palmer, aou, alex, andybnac, andrew.jones,
thecharlesjenkins, linux-kselftest, linux-riscv, linux-kernel
> The regset_data buffer allocated with calloc() in the parent process
> of several vector ptrace tests is never freed before returning,
> causing memory leaks in:
>
> - ptrace_v_not_enabled
> - ptrace_v_early_debug
> - ptrace_v_syscall_clobbering
> - v_csr_invalid/ptrace_v_invalid_values
> - v_csr_valid/ptrace_v_valid_values
>
> Add free(regset_data) before kill(pid, SIGKILL) to release the
> allocated buffer.
>
> Signed-off-by: Wang Yan <wangyan01@kylinos.cn>
> ---
> .../testing/selftests/riscv/vector/validate_v_ptrace.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/tools/testing/selftests/riscv/vector/validate_v_ptrace.c b/tools/testing/selftests/riscv/vector/validate_v_ptrace.c
> index b038e2175c80..a388b7963d47 100644
> --- a/tools/testing/selftests/riscv/vector/validate_v_ptrace.c
> +++ b/tools/testing/selftests/riscv/vector/validate_v_ptrace.c
> @@ -75,7 +75,7 @@ TEST(ptrace_v_not_enabled)
> ASSERT_EQ(-1, ret);
>
> /* cleanup */
> -
> + free(regset_data);
> ASSERT_EQ(0, kill(pid, SIGKILL));
> }
> }
> @@ -207,7 +207,7 @@ TEST(ptrace_v_early_debug)
> EXPECT_EQ(vl_csr, regset_data->vl);
>
> /* cleanup */
> -
> + free(regset_data);
> ASSERT_EQ(0, kill(pid, SIGKILL));
> }
> }
> @@ -331,7 +331,7 @@ TEST(ptrace_v_syscall_clobbering)
> EXPECT_EQ(0UL, regset_data->vl);
>
> /* cleanup */
> -
> + free(regset_data);
> ASSERT_EQ(0, kill(pid, SIGKILL));
> }
> }
> @@ -649,7 +649,7 @@ TEST_F(v_csr_invalid, ptrace_v_invalid_values)
> ASSERT_EQ(ret, -1);
>
> /* cleanup */
> -
> + free(regset_data);
> ASSERT_EQ(0, kill(pid, SIGKILL));
> }
> }
> @@ -911,7 +911,7 @@ TEST_F(v_csr_valid, ptrace_v_valid_values)
> EXPECT_EQ(regset_data->vlenb, vlenb);
>
> /* cleanup */
> -
> + free(regset_data);
> ASSERT_EQ(0, kill(pid, SIGKILL));
> }
> }
Thanks !
Reviewed-by: Sergey Matyukevich <geomatsi@gmai.com>
Regards,
Sergey
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/riscv: ptrace: Fix memory leak of regset_data in vector tests
2026-07-10 8:34 [PATCH] selftests/riscv: ptrace: Fix memory leak of regset_data in vector tests Wang Yan
2026-07-10 10:16 ` Sergey Matyukevich
@ 2026-07-10 15:38 ` Paul Walmsley
1 sibling, 0 replies; 3+ messages in thread
From: Paul Walmsley @ 2026-07-10 15:38 UTC (permalink / raw)
To: Wang Yan
Cc: shuah, pjw, palmer, aou, alex, geomatsi, andybnac, andrew.jones,
thecharlesjenkins, linux-kselftest, linux-riscv, linux-kernel
On Fri, 10 Jul 2026, Wang Yan wrote:
> The regset_data buffer allocated with calloc() in the parent process
> of several vector ptrace tests is never freed before returning,
> causing memory leaks in:
>
> - ptrace_v_not_enabled
> - ptrace_v_early_debug
> - ptrace_v_syscall_clobbering
> - v_csr_invalid/ptrace_v_invalid_values
> - v_csr_valid/ptrace_v_valid_values
>
> Add free(regset_data) before kill(pid, SIGKILL) to release the
> allocated buffer.
>
> Signed-off-by: Wang Yan <wangyan01@kylinos.cn>
Thanks, queued for v7.2-rc.
- Paul
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-10 15:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-10 8:34 [PATCH] selftests/riscv: ptrace: Fix memory leak of regset_data in vector tests Wang Yan
2026-07-10 10:16 ` Sergey Matyukevich
2026-07-10 15:38 ` Paul Walmsley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox