qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tests/unit/test-util-sockets: fix mem-leak on error object
@ 2025-05-26 17:20 Matheus Tavares Bernardino
  2025-05-27  8:43 ` Juraj Marcin
  2025-05-30 15:37 ` Daniel P. Berrangé
  0 siblings, 2 replies; 3+ messages in thread
From: Matheus Tavares Bernardino @ 2025-05-26 17:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: jmarcin, qemu-trivial, berrange, pbonzini, vsementsov, brian.cain

The test fails with --enable-asan as the error struct is never freed.
In the case where the test expects a success but it fails, let's also
report the error for debugging (it will be freed internally).

Fixes 316e8ee8d6 ("util/qemu-sockets: Refactor inet_parse() to use QemuOpts")
Signed-off-by: Matheus Tavares Bernardino <matheus.bernardino@oss.qualcomm.com>
---
 tests/unit/test-util-sockets.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c
index 8492f4d68f..ee66d727c3 100644
--- a/tests/unit/test-util-sockets.c
+++ b/tests/unit/test-util-sockets.c
@@ -341,8 +341,12 @@ static void inet_parse_test_helper(const char *str,
     int rc = inet_parse(&addr, str, &error);
 
     if (success) {
+        if (error) {
+            error_report_err(error);
+        }
         g_assert_cmpint(rc, ==, 0);
     } else {
+        error_free(error);
         g_assert_cmpint(rc, <, 0);
     }
     if (exp_addr != NULL) {
-- 
2.37.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tests/unit/test-util-sockets: fix mem-leak on error object
  2025-05-26 17:20 [PATCH] tests/unit/test-util-sockets: fix mem-leak on error object Matheus Tavares Bernardino
@ 2025-05-27  8:43 ` Juraj Marcin
  2025-05-30 15:37 ` Daniel P. Berrangé
  1 sibling, 0 replies; 3+ messages in thread
From: Juraj Marcin @ 2025-05-27  8:43 UTC (permalink / raw)
  To: Matheus Tavares Bernardino
  Cc: qemu-devel, qemu-trivial, berrange, pbonzini, vsementsov,
	brian.cain

Hi Matheus

On 2025-05-26 10:20, Matheus Tavares Bernardino wrote:
> The test fails with --enable-asan as the error struct is never freed.
> In the case where the test expects a success but it fails, let's also
> report the error for debugging (it will be freed internally).

Oh, nice catch. Thanks!

Reviewed-by: Juraj Marcin <jmarcin@redhat.com>

> 
> Fixes 316e8ee8d6 ("util/qemu-sockets: Refactor inet_parse() to use QemuOpts")
> Signed-off-by: Matheus Tavares Bernardino <matheus.bernardino@oss.qualcomm.com>
> ---
>  tests/unit/test-util-sockets.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c
> index 8492f4d68f..ee66d727c3 100644
> --- a/tests/unit/test-util-sockets.c
> +++ b/tests/unit/test-util-sockets.c
> @@ -341,8 +341,12 @@ static void inet_parse_test_helper(const char *str,
>      int rc = inet_parse(&addr, str, &error);
>  
>      if (success) {
> +        if (error) {
> +            error_report_err(error);
> +        }
>          g_assert_cmpint(rc, ==, 0);
>      } else {
> +        error_free(error);
>          g_assert_cmpint(rc, <, 0);
>      }
>      if (exp_addr != NULL) {
> -- 
> 2.37.2
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tests/unit/test-util-sockets: fix mem-leak on error object
  2025-05-26 17:20 [PATCH] tests/unit/test-util-sockets: fix mem-leak on error object Matheus Tavares Bernardino
  2025-05-27  8:43 ` Juraj Marcin
@ 2025-05-30 15:37 ` Daniel P. Berrangé
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel P. Berrangé @ 2025-05-30 15:37 UTC (permalink / raw)
  To: Matheus Tavares Bernardino
  Cc: qemu-devel, jmarcin, qemu-trivial, pbonzini, vsementsov,
	brian.cain

On Mon, May 26, 2025 at 10:20:55AM -0700, Matheus Tavares Bernardino wrote:
> The test fails with --enable-asan as the error struct is never freed.
> In the case where the test expects a success but it fails, let's also
> report the error for debugging (it will be freed internally).
> 
> Fixes 316e8ee8d6 ("util/qemu-sockets: Refactor inet_parse() to use QemuOpts")
> Signed-off-by: Matheus Tavares Bernardino <matheus.bernardino@oss.qualcomm.com>
> ---
>  tests/unit/test-util-sockets.c | 4 ++++
>  1 file changed, 4 insertions(+)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-30 15:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-26 17:20 [PATCH] tests/unit/test-util-sockets: fix mem-leak on error object Matheus Tavares Bernardino
2025-05-27  8:43 ` Juraj Marcin
2025-05-30 15:37 ` Daniel P. Berrangé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).