[PATCH 1/7] tests/qtest/npcm7xx_emc_test: Don't leak cmd_line

Peter Maydell posted 7 patches 1 year, 11 months ago
Maintainers: Glenn Miles <milesg@linux.vnet.ibm.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Ilya Maximets <i.maximets@ovn.org>, Jason Wang <jasowang@redhat.com>, Thomas Huth <thuth@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Tyrone Ting <kfting@nuvoton.com>, Hao Wu <wuhaotsh@google.com>, Alberto Garcia <berto@igalia.com>
[PATCH 1/7] tests/qtest/npcm7xx_emc_test: Don't leak cmd_line
Posted by Peter Maydell 1 year, 11 months ago
In test_rx() and test_tx() we allocate a GString *cmd_line
but never free it. This is pretty harmless in a test case, but
Coverity spotted it.

Resolves: Coverity CID 1507122
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 tests/qtest/npcm7xx_emc-test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/qtest/npcm7xx_emc-test.c b/tests/qtest/npcm7xx_emc-test.c
index 63f6cadb5cc..2e1a1a6d702 100644
--- a/tests/qtest/npcm7xx_emc-test.c
+++ b/tests/qtest/npcm7xx_emc-test.c
@@ -789,7 +789,7 @@ static void emc_test_ptle(QTestState *qts, const EMCModule *mod, int fd)
 static void test_tx(gconstpointer test_data)
 {
     const TestData *td = test_data;
-    GString *cmd_line = g_string_new("-machine quanta-gsj");
+    g_autoptr(GString) cmd_line = g_string_new("-machine quanta-gsj");
     int *test_sockets = packet_test_init(emc_module_index(td->module),
                                          cmd_line);
     QTestState *qts = qtest_init(cmd_line->str);
@@ -814,7 +814,7 @@ static void test_tx(gconstpointer test_data)
 static void test_rx(gconstpointer test_data)
 {
     const TestData *td = test_data;
-    GString *cmd_line = g_string_new("-machine quanta-gsj");
+    g_autoptr(GString) cmd_line = g_string_new("-machine quanta-gsj");
     int *test_sockets = packet_test_init(emc_module_index(td->module),
                                          cmd_line);
     QTestState *qts = qtest_init(cmd_line->str);
-- 
2.34.1
Re: [PATCH 1/7] tests/qtest/npcm7xx_emc_test: Don't leak cmd_line
Posted by Thomas Huth 1 year, 11 months ago
On 12/03/2024 19.38, Peter Maydell wrote:
> In test_rx() and test_tx() we allocate a GString *cmd_line
> but never free it. This is pretty harmless in a test case, but
> Coverity spotted it.
> 
> Resolves: Coverity CID 1507122
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   tests/qtest/npcm7xx_emc-test.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qtest/npcm7xx_emc-test.c b/tests/qtest/npcm7xx_emc-test.c
> index 63f6cadb5cc..2e1a1a6d702 100644
> --- a/tests/qtest/npcm7xx_emc-test.c
> +++ b/tests/qtest/npcm7xx_emc-test.c
> @@ -789,7 +789,7 @@ static void emc_test_ptle(QTestState *qts, const EMCModule *mod, int fd)
>   static void test_tx(gconstpointer test_data)
>   {
>       const TestData *td = test_data;
> -    GString *cmd_line = g_string_new("-machine quanta-gsj");
> +    g_autoptr(GString) cmd_line = g_string_new("-machine quanta-gsj");
>       int *test_sockets = packet_test_init(emc_module_index(td->module),
>                                            cmd_line);
>       QTestState *qts = qtest_init(cmd_line->str);
> @@ -814,7 +814,7 @@ static void test_tx(gconstpointer test_data)
>   static void test_rx(gconstpointer test_data)
>   {
>       const TestData *td = test_data;
> -    GString *cmd_line = g_string_new("-machine quanta-gsj");
> +    g_autoptr(GString) cmd_line = g_string_new("-machine quanta-gsj");
>       int *test_sockets = packet_test_init(emc_module_index(td->module),
>                                            cmd_line);
>       QTestState *qts = qtest_init(cmd_line->str);

Reviewed-by: Thomas Huth <thuth@redhat.com>
Re: [PATCH 1/7] tests/qtest/npcm7xx_emc_test: Don't leak cmd_line
Posted by Thomas Huth 1 year, 11 months ago
On 12/03/2024 19.38, Peter Maydell wrote:
> In test_rx() and test_tx() we allocate a GString *cmd_line
> but never free it. This is pretty harmless in a test case, but
> Coverity spotted it.
> 
> Resolves: Coverity CID 1507122
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   tests/qtest/npcm7xx_emc-test.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qtest/npcm7xx_emc-test.c b/tests/qtest/npcm7xx_emc-test.c
> index 63f6cadb5cc..2e1a1a6d702 100644
> --- a/tests/qtest/npcm7xx_emc-test.c
> +++ b/tests/qtest/npcm7xx_emc-test.c
> @@ -789,7 +789,7 @@ static void emc_test_ptle(QTestState *qts, const EMCModule *mod, int fd)
>   static void test_tx(gconstpointer test_data)
>   {
>       const TestData *td = test_data;
> -    GString *cmd_line = g_string_new("-machine quanta-gsj");
> +    g_autoptr(GString) cmd_line = g_string_new("-machine quanta-gsj");
>       int *test_sockets = packet_test_init(emc_module_index(td->module),
>                                            cmd_line);
>       QTestState *qts = qtest_init(cmd_line->str);
> @@ -814,7 +814,7 @@ static void test_tx(gconstpointer test_data)
>   static void test_rx(gconstpointer test_data)
>   {
>       const TestData *td = test_data;
> -    GString *cmd_line = g_string_new("-machine quanta-gsj");
> +    g_autoptr(GString) cmd_line = g_string_new("-machine quanta-gsj");
>       int *test_sockets = packet_test_init(emc_module_index(td->module),
>                                            cmd_line);
>       QTestState *qts = qtest_init(cmd_line->str);

Reviewed-by: Thomas Huth <thuth@redhat.com>