From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 339B6C47082 for ; Tue, 8 Jun 2021 19:52:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E2AC61375 for ; Tue, 8 Jun 2021 19:52:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E2AC61375 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqhmP-0008NO-BR for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 15:52:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqhlV-0007iw-Hh for qemu-devel@nongnu.org; Tue, 08 Jun 2021 15:51:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37543) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqhlR-0001MR-2Y for qemu-devel@nongnu.org; Tue, 08 Jun 2021 15:51:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623181909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eZLIC/QNbah6MxxKEZxHZYf0R0MgusHf4MieqgC9lro=; b=aec+B4OGWac2KQtA9c/yJwvwyW+udIu55vwD0dvGhJ6kyO2oK/lPFSUzJMNkOHkVqAeW6B NwGUq7asMhsr/Hqd1FOasbsw13qtGZMAUwjAb06143fwfzi0e8qIu5Li4PXDNh22hHqzux N6JFhsrYE93pdFcGkNdodate+Bl+5j8= Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-172-dkIa1CBbOrqo67zk7J8dMQ-1; Tue, 08 Jun 2021 15:51:48 -0400 X-MC-Unique: dkIa1CBbOrqo67zk7J8dMQ-1 Received: by mail-pg1-f199.google.com with SMTP id x7-20020a63db470000b029022199758419so724821pgi.11 for ; Tue, 08 Jun 2021 12:51:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eZLIC/QNbah6MxxKEZxHZYf0R0MgusHf4MieqgC9lro=; b=WU6gBAYbfM19zrPrrvFbG7lVk19fL2/4+71DuNOYL9p8saRjxZol/meMcVvURusUj9 A10MIyENCwIIEyQzcmlPLb9k7CcDgpNU+KPdZcasb1rlM4dpC4NCxEpXOxkDMdbWTfNL Br5TyDKCMBxElpjKfO+iFbD8mZIshMIi4dEYi0ForPcDknKzJ1ELpz2+vEZgo0VpqE1m VjUnnMP8PDBg+L0JonMiabwIgxQJMvFUz3gHZq6RVv4sBTD8N6fp2baHA8udQdNw98j4 omvgEtIKIf/BbuwPRWMw+QFTfw0WjBUzUHaNWYBog431op2lESVhj5IX7SUz4F67w5zb BYZA== X-Gm-Message-State: AOAM533he+OI5sdvrhR4DNOx+COT4nL6uKL2z65YGRX+gPy0yhny1W2x SSEXxyOYUS5f0GTyY2xhvQllMCr57YkeCzDBARSkSkmgzAufR/n+qmZ4eKkn18pUknoOKfCLXrj q/ytvFou683Xt8VaorHekgMfh2/O4sug= X-Received: by 2002:a65:638e:: with SMTP id h14mr24392953pgv.108.1623181906807; Tue, 08 Jun 2021 12:51:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIpwOhS58KCUXJ6YR1EVgztb4GD4PNuRkyruP6Jg8XWVUBmpDEjLzmUZoMmMcCZb3XF/CTs3J39XzjI5j29Vo= X-Received: by 2002:a65:638e:: with SMTP id h14mr24392924pgv.108.1623181906512; Tue, 08 Jun 2021 12:51:46 -0700 (PDT) MIME-Version: 1.0 References: <20210608170607.21902-1-peter.maydell@linaro.org> In-Reply-To: <20210608170607.21902-1-peter.maydell@linaro.org> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Tue, 8 Jun 2021 23:51:35 +0400 Message-ID: Subject: Re: [PATCH] tests/unit/test-char.c: Fix error handling issues To: Peter Maydell Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mlureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="000000000000f19fde05c4467c18" Received-SPF: pass client-ip=170.10.133.124; envelope-from=mlureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.197, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?Q?Daniel_P=2E_Berrang=C3=A9?= , Richard Henderson , qemu-devel , Markus Armbruster , Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --000000000000f19fde05c4467c18 Content-Type: text/plain; charset="UTF-8" Hi On Tue, Jun 8, 2021 at 9:06 PM Peter Maydell wrote: > Coverity spots some minor error-handling issues in this test code. > These are mostly due to the test code assuming that the glib test > macros g_assert_cmpint() and friends will always abort on failure. > This is not the case: if the test case chooses to call > g_test_set_nonfatal_assertions() then they will mark the test case as > a failure and continue. (This is different to g_assert(), > g_assert_not_reached(), and assert(), which really do all always kill > the process.) The idea is that you use g_assert() for things > which are really assertions, as you would in normal QEMU code, > and g_assert_cmpint() and friends for "this check is the thing > this test case is testing" checks. > > In fact this test case does not currently set assertions to be > nonfatal, but we should ideally be aiming to get to a point where we > can set that more generally, because the test harness gives much > better error reporting (including minor details like "what was the > name of the test case that actually failed") than a raw assert/abort > does. So we mostly fix the Coverity nits by making the error-exit > path return early if necessary, rather than by converting the > g_assert_cmpint()s to g_assert()s. > > Fixes: Coverity CID 1432505, 1432514, 1432600, 1451384 > Signed-off-by: Peter Maydell > --- > We had some previous not-very-conclusive discussion about > g_assert_foo vs g_assert in this thread: > > https://lore.kernel.org/qemu-devel/CAFEAcA9juOChqrh5orybJQwpQsyEZ5z3Dvmy7fjX0DW4Nbgmrg@mail.gmail.com/ > This patch is in some sense me asserting my opinion about the > right thing to do. You might disagree... > > I think that improving the quality of the failure reporting > in 'make check' is useful, and that we should probably turn > on g_test_set_nonfatal_assertions() everywhere. (The worst that > can happen is that instead of crashing on the assert we proceed > and crash a bit later, I think.) Awkwardly we don't have a single > place where we could put that call, so I guess it's a coccinelle > script to add it to every test's main() function. > > I don't have any strong opinion on this. But I don't see much sense in having extra code for things that should never happen. I would teach coverity instead that those asserts are always fatal. aborting right where the assert is reached is easier for the developer, as you get a direct backtrace. Given that tests are usually grouped in domains, it doesn't help much to keep running the rest of the tests in that group anyway. Fwiw, none of the tests in glib or gtk seem to use g_test_set_nonfatal_assertions(), probably for similar considerations. tests/unit/test-char.c | 36 ++++++++++++++++++++++++++++++++++-- > 1 file changed, 34 insertions(+), 2 deletions(-) > > diff --git a/tests/unit/test-char.c b/tests/unit/test-char.c > index 5b3b48ebacd..43630ab57f8 100644 > --- a/tests/unit/test-char.c > +++ b/tests/unit/test-char.c > @@ -214,6 +214,10 @@ static void char_mux_test(void) > qemu_chr_fe_take_focus(&chr_be2); > > base = qemu_chr_find("mux-label-base"); > + g_assert_nonnull(base); > + if (base == 0) { > + goto fail; > + } > g_assert_cmpint(qemu_chr_be_can_write(base), !=, 0); > > qemu_chr_be_write(base, (void *)"hello", 6); > @@ -333,6 +337,7 @@ static void char_mux_test(void) > g_assert_cmpint(strlen(data), !=, 0); > g_free(data); > > +fail: > qemu_chr_fe_deinit(&chr_be1, false); > qemu_chr_fe_deinit(&chr_be2, true); > } > @@ -486,6 +491,9 @@ static void char_pipe_test(void) > chr = qemu_chr_new("pipe", tmp, NULL); > g_assert_nonnull(chr); > g_free(tmp); > + if (!chr) { > + goto fail; > + } > > qemu_chr_fe_init(&be, chr, &error_abort); > > @@ -493,12 +501,20 @@ static void char_pipe_test(void) > g_assert_cmpint(ret, ==, 9); > > fd = open(out, O_RDWR); > + g_assert_cmpint(fd, >=, 0); > + if (fd < 0) { > + goto fail; > + } > ret = read(fd, buf, sizeof(buf)); > g_assert_cmpint(ret, ==, 9); > g_assert_cmpstr(buf, ==, "pipe-out"); > close(fd); > > fd = open(in, O_WRONLY); > + g_assert_cmpint(fd, >=, 0); > + if (fd < 0) { > + goto fail; > + } > ret = write(fd, "pipe-in", 8); > g_assert_cmpint(ret, ==, 8); > close(fd); > @@ -518,6 +534,7 @@ static void char_pipe_test(void) > > qemu_chr_fe_deinit(&be, true); > > +fail: > g_assert(g_unlink(in) == 0); > g_assert(g_unlink(out) == 0); > g_assert(g_rmdir(tmp_path) == 0); > @@ -556,7 +573,10 @@ static int make_udp_socket(int *port) > socklen_t alen = sizeof(addr); > int ret, sock = qemu_socket(PF_INET, SOCK_DGRAM, 0); > > - g_assert_cmpint(sock, >, 0); > + g_assert_cmpint(sock, >=, 0); > + if (sock < 0) { > + return sock; > + } > addr.sin_family = AF_INET ; > addr.sin_addr.s_addr = htonl(INADDR_ANY); > addr.sin_port = 0; > @@ -586,6 +606,9 @@ static void char_udp_test_internal(Chardev *reuse_chr, > int sock) > } else { > int port; > sock = make_udp_socket(&port); > + if (sock < 0) { > + return; > + } > tmp = g_strdup_printf("udp:127.0.0.1:%d", port); > chr = qemu_chr_new("client", tmp, NULL); > g_assert_nonnull(chr); > @@ -1224,6 +1247,10 @@ static void char_file_fifo_test(void) > } > > fd = open(fifo, O_RDWR); > + g_assert_cmpint(fd, >=, 0); > + if (fd < 0) { > + goto fail; > + } > ret = write(fd, "fifo-in", 8); > g_assert_cmpint(ret, ==, 8); > > @@ -1253,6 +1280,7 @@ static void char_file_fifo_test(void) > > qemu_chr_fe_deinit(&be, true); > > +fail: > g_unlink(fifo); > g_free(fifo); > g_unlink(out); > @@ -1371,7 +1399,7 @@ static int chardev_change_denied(void *opaque) > > static void char_hotswap_test(void) > { > - char *chr_args; > + char *chr_args = NULL; > Chardev *chr; > CharBackend be; > > @@ -1385,6 +1413,9 @@ static void char_hotswap_test(void) > int port; > int sock = make_udp_socket(&port); > g_assert_cmpint(sock, >, 0); > + if (sock < 0) { > + goto fail; > + } > > chr_args = g_strdup_printf("udp:127.0.0.1:%d", port); > > @@ -1422,6 +1453,7 @@ static void char_hotswap_test(void) > object_unparent(OBJECT(chr)); > > qapi_free_ChardevReturn(ret); > +fail: > g_unlink(filename); > g_free(filename); > g_rmdir(tmp_path); > -- > 2.20.1 > > --000000000000f19fde05c4467c18 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

On Tue, Jun 8, 2021 at 9:06 PM Pete= r Maydell <peter.maydell@lin= aro.org> wrote:
Coverity spots some minor error-handling issues in this test code. These are mostly due to the test code assuming that the glib test
macros g_assert_cmpint() and friends will always abort on failure.
This is not the case: if the test case chooses to call
g_test_set_nonfatal_assertions() then they will mark the test case as
a failure and continue.=C2=A0 (This is different to g_assert(),
g_assert_not_reached(), and assert(), which really do all always kill
the process.) The idea is that you use g_assert() for things
which are really assertions, as you would in normal QEMU code,
and g_assert_cmpint() and friends for "this check is the thing
this test case is testing" checks.

In fact this test case does not currently set assertions to be
nonfatal, but we should ideally be aiming to get to a point where we
can set that more generally, because the test harness gives much
better error reporting (including minor details like "what was the
name of the test case that actually failed") than a raw assert/abort does.=C2=A0 So we mostly fix the Coverity nits by making the error-exit
path return early if necessary, rather than by converting the
g_assert_cmpint()s to g_assert()s.

Fixes: Coverity CID 1432505, 1432514, 1432600, 1451384
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
We had some previous not-very-conclusive discussion about
g_assert_foo vs g_assert in this thread:
https://lore.kernel.org/qemu-devel/CAFEAcA9juOChqrh5orybJQwpQsyEZ5z3Dvmy7= fjX0DW4Nbgmrg@mail.gmail.com/
This patch is in some sense me asserting my opinion about the
right thing to do. You might disagree...

I think that improving the quality of the failure reporting
in 'make check' is useful, and that we should probably turn
on g_test_set_nonfatal_assertions() everywhere. (The worst that
can happen is that instead of crashing on the assert we proceed
and crash a bit later, I think.) Awkwardly we don't have a single
place where we could put that call, so I guess it's a coccinelle
script to add it to every test's main() function.


I don't have any strong opinion on= this. But I don't see much sense in having extra code for things that = should never happen. I would teach coverity instead that those asserts are = always fatal. aborting right where the assert is reached is easier for the = developer, as you get a direct backtrace. Given that tests are usually grou= ped in domains, it doesn't help much to keep running the rest of the te= sts in that group anyway.

Fwiw, none of the te= sts in glib or gtk seem to use g_test_set_nonfatal_assertions(), probably f= or similar considerations.

=C2=A0tests/unit/test-char.c | 36 ++++++++++++++++++++++++++++++++++--
=C2=A01 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/tests/unit/test-char.c b/tests/unit/test-char.c
index 5b3b48ebacd..43630ab57f8 100644
--- a/tests/unit/test-char.c
+++ b/tests/unit/test-char.c
@@ -214,6 +214,10 @@ static void char_mux_test(void)
=C2=A0 =C2=A0 =C2=A0qemu_chr_fe_take_focus(&chr_be2);

=C2=A0 =C2=A0 =C2=A0base =3D qemu_chr_find("mux-label-base");
+=C2=A0 =C2=A0 g_assert_nonnull(base);
+=C2=A0 =C2=A0 if (base =3D=3D 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 goto fail;
+=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0g_assert_cmpint(qemu_chr_be_can_write(base), !=3D, 0);<= br>
=C2=A0 =C2=A0 =C2=A0qemu_chr_be_write(base, (void *)"hello", 6);<= br> @@ -333,6 +337,7 @@ static void char_mux_test(void)
=C2=A0 =C2=A0 =C2=A0g_assert_cmpint(strlen(data), !=3D, 0);
=C2=A0 =C2=A0 =C2=A0g_free(data);

+fail:
=C2=A0 =C2=A0 =C2=A0qemu_chr_fe_deinit(&chr_be1, false);
=C2=A0 =C2=A0 =C2=A0qemu_chr_fe_deinit(&chr_be2, true);
=C2=A0}
@@ -486,6 +491,9 @@ static void char_pipe_test(void)
=C2=A0 =C2=A0 =C2=A0chr =3D qemu_chr_new("pipe", tmp, NULL);
=C2=A0 =C2=A0 =C2=A0g_assert_nonnull(chr);
=C2=A0 =C2=A0 =C2=A0g_free(tmp);
+=C2=A0 =C2=A0 if (!chr) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 goto fail;
+=C2=A0 =C2=A0 }

=C2=A0 =C2=A0 =C2=A0qemu_chr_fe_init(&be, chr, &error_abort);

@@ -493,12 +501,20 @@ static void char_pipe_test(void)
=C2=A0 =C2=A0 =C2=A0g_assert_cmpint(ret, =3D=3D, 9);

=C2=A0 =C2=A0 =C2=A0fd =3D open(out, O_RDWR);
+=C2=A0 =C2=A0 g_assert_cmpint(fd, >=3D, 0);
+=C2=A0 =C2=A0 if (fd < 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 goto fail;
+=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0ret =3D read(fd, buf, sizeof(buf));
=C2=A0 =C2=A0 =C2=A0g_assert_cmpint(ret, =3D=3D, 9);
=C2=A0 =C2=A0 =C2=A0g_assert_cmpstr(buf, =3D=3D, "pipe-out");
=C2=A0 =C2=A0 =C2=A0close(fd);

=C2=A0 =C2=A0 =C2=A0fd =3D open(in, O_WRONLY);
+=C2=A0 =C2=A0 g_assert_cmpint(fd, >=3D, 0);
+=C2=A0 =C2=A0 if (fd < 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 goto fail;
+=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0ret =3D write(fd, "pipe-in", 8);
=C2=A0 =C2=A0 =C2=A0g_assert_cmpint(ret, =3D=3D, 8);
=C2=A0 =C2=A0 =C2=A0close(fd);
@@ -518,6 +534,7 @@ static void char_pipe_test(void)

=C2=A0 =C2=A0 =C2=A0qemu_chr_fe_deinit(&be, true);

+fail:
=C2=A0 =C2=A0 =C2=A0g_assert(g_unlink(in) =3D=3D 0);
=C2=A0 =C2=A0 =C2=A0g_assert(g_unlink(out) =3D=3D 0);
=C2=A0 =C2=A0 =C2=A0g_assert(g_rmdir(tmp_path) =3D=3D 0);
@@ -556,7 +573,10 @@ static int make_udp_socket(int *port)
=C2=A0 =C2=A0 =C2=A0socklen_t alen =3D sizeof(addr);
=C2=A0 =C2=A0 =C2=A0int ret, sock =3D qemu_socket(PF_INET, SOCK_DGRAM, 0);<= br>
-=C2=A0 =C2=A0 g_assert_cmpint(sock, >, 0);
+=C2=A0 =C2=A0 g_assert_cmpint(sock, >=3D, 0);
+=C2=A0 =C2=A0 if (sock < 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return sock;
+=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0addr.sin_family =3D AF_INET ;
=C2=A0 =C2=A0 =C2=A0addr.sin_addr.s_addr =3D htonl(INADDR_ANY);
=C2=A0 =C2=A0 =C2=A0addr.sin_port =3D 0;
@@ -586,6 +606,9 @@ static void char_udp_test_internal(Chardev *reuse_chr, = int sock)
=C2=A0 =C2=A0 =C2=A0} else {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int port;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sock =3D make_udp_socket(&port);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (sock < 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tmp =3D g_strdup_printf("udp:127.0.0= .1:%d", port);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0chr =3D qemu_chr_new("client", = tmp, NULL);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0g_assert_nonnull(chr);
@@ -1224,6 +1247,10 @@ static void char_file_fifo_test(void)
=C2=A0 =C2=A0 =C2=A0}

=C2=A0 =C2=A0 =C2=A0fd =3D open(fifo, O_RDWR);
+=C2=A0 =C2=A0 g_assert_cmpint(fd, >=3D, 0);
+=C2=A0 =C2=A0 if (fd < 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 goto fail;
+=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0ret =3D write(fd, "fifo-in", 8);
=C2=A0 =C2=A0 =C2=A0g_assert_cmpint(ret, =3D=3D, 8);

@@ -1253,6 +1280,7 @@ static void char_file_fifo_test(void)

=C2=A0 =C2=A0 =C2=A0qemu_chr_fe_deinit(&be, true);

+fail:
=C2=A0 =C2=A0 =C2=A0g_unlink(fifo);
=C2=A0 =C2=A0 =C2=A0g_free(fifo);
=C2=A0 =C2=A0 =C2=A0g_unlink(out);
@@ -1371,7 +1399,7 @@ static int chardev_change_denied(void *opaque)

=C2=A0static void char_hotswap_test(void)
=C2=A0{
-=C2=A0 =C2=A0 char *chr_args;
+=C2=A0 =C2=A0 char *chr_args =3D NULL;
=C2=A0 =C2=A0 =C2=A0Chardev *chr;
=C2=A0 =C2=A0 =C2=A0CharBackend be;

@@ -1385,6 +1413,9 @@ static void char_hotswap_test(void)
=C2=A0 =C2=A0 =C2=A0int port;
=C2=A0 =C2=A0 =C2=A0int sock =3D make_udp_socket(&port);
=C2=A0 =C2=A0 =C2=A0g_assert_cmpint(sock, >, 0);
+=C2=A0 =C2=A0 if (sock < 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 goto fail;
+=C2=A0 =C2=A0 }

=C2=A0 =C2=A0 =C2=A0chr_args =3D g_strdup_printf("udp:127.0.0.1:%d&quo= t;, port);

@@ -1422,6 +1453,7 @@ static void char_hotswap_test(void)
=C2=A0 =C2=A0 =C2=A0object_unparent(OBJECT(chr));

=C2=A0 =C2=A0 =C2=A0qapi_free_ChardevReturn(ret);
+fail:
=C2=A0 =C2=A0 =C2=A0g_unlink(filename);
=C2=A0 =C2=A0 =C2=A0g_free(filename);
=C2=A0 =C2=A0 =C2=A0g_rmdir(tmp_path);
--
2.20.1

--000000000000f19fde05c4467c18--