From nobody Sat Apr 27 02:07:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595979669; cv=none; d=zohomail.com; s=zohoarc; b=WLkpus02TaFZRLBeeDWCUfccyVtwoKTJGMAtMLf4ReVLofllZBEgHCDsEWrXuNCbzw+0ZZkN5dhZ5q2wKSNKEKVeptZLvsWiWGCcmGQzkof/xWNM6xMqu/ef1aaTMC8DqGV9zndWOz3tbUs3pyEjvoQDLucmpJ3DDvF6wHKBR+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595979669; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GvTalUL6vAlp5SoaI0rXr7h1YKRK1lRrg27PtjIg7HI=; b=YdmITbV1GMZ6RjRg7zNt7eM+E0l2jJBjxvS1sQlSVUpdfyvp83AC21eKWbxcsOIrAfvnLXJ3MyT0QJ0SwBr6JHLRNtEKx5KSAFwG/M4RDB9MgEe6KJNprY1e065EuXTQsl7KRSoaowX8i3a4eVgfkMbLlLp4YlEcmcer8Ajoui0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1595979669453140.79309608470157; Tue, 28 Jul 2020 16:41:09 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-300-vp2YYds5P8iPiAujb8VAAw-1; Tue, 28 Jul 2020 19:41:04 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2C7D800688; Tue, 28 Jul 2020 23:40:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 805EB10013C4; Tue, 28 Jul 2020 23:40:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 499411809561; Tue, 28 Jul 2020 23:40:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06SNetkh003856 for ; Tue, 28 Jul 2020 19:40:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 85E3A79251; Tue, 28 Jul 2020 23:40:55 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id D24798A164 for ; Tue, 28 Jul 2020 23:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595979668; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=GvTalUL6vAlp5SoaI0rXr7h1YKRK1lRrg27PtjIg7HI=; b=NkUvgyskGvtr3JW0kMspx2J85JGKR+hqgHxpR53Aadm08SH9ewJoSaTvhFNJ0exNN2ayGr 6Wy296cHGQkljVIft2U1WXbqZx+4CX4+Drqk8SPCPLEALcdDxLX8fdRx5949xvZDkz3BrL 7NRx/kR5ZS51LbQ9h3NDJTGuiSkmA3A= X-MC-Unique: vp2YYds5P8iPiAujb8VAAw-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/5] tests: commandtest: remove unused 'prefix' parameter Date: Wed, 29 Jul 2020 01:40:44 +0200 Message-Id: <4b59094cc867e2eef63255956e4a4bb8ee01895a.1595979625.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) The 'checkoutput' function does have a parameter for a possible prefix, but it is now unused. Introduced-by: 241ac07124a3172dc38198d777eb3f04846f6c52 Used-by: 62f263a73e8202f2af7309d10000a3b9a66e6b57 Unused-since: 2dfacbffea47743fff942b6401f5f36b3ae4655a Signed-off-by: J=C3=A1n Tomko Reviewed-by: Laine Stump --- tests/commandtest.c | 52 ++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/tests/commandtest.c b/tests/commandtest.c index 9bef825239..a18100a705 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -55,8 +55,7 @@ main(void) /* Some UNIX lack it in headers & it doesn't hurt to redeclare */ extern char **environ; =20 -static int checkoutput(const char *testname, - char *prefix) +static int checkoutput(const char *testname) { int ret =3D -1; char *expectname =3D NULL; @@ -77,15 +76,6 @@ static int checkoutput(const char *testname, goto cleanup; } =20 - if (prefix) { - char *tmp =3D NULL; - - tmp =3D g_strdup_printf("%s%s", prefix, expectlog); - - VIR_FREE(expectlog); - expectlog =3D tmp; - } - if (STRNEQ(expectlog, actuallog)) { virTestDifference(stderr, expectlog, actuallog); goto cleanup; @@ -172,7 +162,7 @@ static int test2(const void *unused G_GNUC_UNUSED) return -1; } =20 - if ((ret =3D checkoutput("test2", NULL)) !=3D 0) { + if ((ret =3D checkoutput("test2")) !=3D 0) { virCommandFree(cmd); return ret; } @@ -185,7 +175,7 @@ static int test2(const void *unused G_GNUC_UNUSED) =20 virCommandFree(cmd); =20 - return checkoutput("test2", NULL); + return checkoutput("test2"); } =20 /* @@ -237,7 +227,7 @@ static int test3(const void *unused G_GNUC_UNUSED) } } =20 - ret =3D checkoutput("test3", NULL); + ret =3D checkoutput("test3"); =20 cleanup: virCommandFree(cmd); @@ -279,7 +269,7 @@ static int test4(const void *unused G_GNUC_UNUSED) while (kill(pid, 0) !=3D -1) g_usleep(100*1000); =20 - ret =3D checkoutput("test4", NULL); + ret =3D checkoutput("test4"); =20 cleanup: virCommandFree(cmd); @@ -308,7 +298,7 @@ static int test5(const void *unused G_GNUC_UNUSED) =20 virCommandFree(cmd); =20 - return checkoutput("test5", NULL); + return checkoutput("test5"); } =20 =20 @@ -331,7 +321,7 @@ static int test6(const void *unused G_GNUC_UNUSED) =20 virCommandFree(cmd); =20 - return checkoutput("test6", NULL); + return checkoutput("test6"); } =20 =20 @@ -355,7 +345,7 @@ static int test7(const void *unused G_GNUC_UNUSED) =20 virCommandFree(cmd); =20 - return checkoutput("test7", NULL); + return checkoutput("test7"); } =20 /* @@ -379,7 +369,7 @@ static int test8(const void *unused G_GNUC_UNUSED) =20 virCommandFree(cmd); =20 - return checkoutput("test8", NULL); + return checkoutput("test8"); } =20 =20 @@ -415,7 +405,7 @@ static int test9(const void *unused G_GNUC_UNUSED) =20 virCommandFree(cmd); =20 - return checkoutput("test9", NULL); + return checkoutput("test9"); } =20 =20 @@ -440,7 +430,7 @@ static int test10(const void *unused G_GNUC_UNUSED) =20 virCommandFree(cmd); =20 - return checkoutput("test10", NULL); + return checkoutput("test10"); } =20 /* @@ -463,7 +453,7 @@ static int test11(const void *unused G_GNUC_UNUSED) =20 virCommandFree(cmd); =20 - return checkoutput("test11", NULL); + return checkoutput("test11"); } =20 /* @@ -484,7 +474,7 @@ static int test12(const void *unused G_GNUC_UNUSED) =20 virCommandFree(cmd); =20 - return checkoutput("test12", NULL); + return checkoutput("test12"); } =20 /* @@ -518,7 +508,7 @@ static int test13(const void *unused G_GNUC_UNUSED) goto cleanup; } =20 - ret =3D checkoutput("test13", NULL); + ret =3D checkoutput("test13"); =20 cleanup: virCommandFree(cmd); @@ -588,7 +578,7 @@ static int test14(const void *unused G_GNUC_UNUSED) goto cleanup; } =20 - ret =3D checkoutput("test14", NULL); + ret =3D checkoutput("test14"); =20 cleanup: virCommandFree(cmd); @@ -618,7 +608,7 @@ static int test15(const void *unused G_GNUC_UNUSED) goto cleanup; } =20 - ret =3D checkoutput("test15", NULL); + ret =3D checkoutput("test15"); =20 cleanup: VIR_FREE(cwd); @@ -663,7 +653,7 @@ static int test16(const void *unused G_GNUC_UNUSED) goto cleanup; } =20 - ret =3D checkoutput("test16", NULL); + ret =3D checkoutput("test16"); =20 cleanup: virCommandFree(cmd); @@ -836,7 +826,7 @@ static int test20(const void *unused G_GNUC_UNUSED) goto cleanup; } =20 - ret =3D checkoutput("test20", NULL); + ret =3D checkoutput("test20"); cleanup: virCommandFree(cmd); VIR_FREE(buf); @@ -894,7 +884,7 @@ static int test21(const void *unused G_GNUC_UNUSED) goto cleanup; } =20 - ret =3D checkoutput("test21", NULL); + ret =3D checkoutput("test21"); cleanup: VIR_FREE(outbuf); VIR_FREE(errbuf); @@ -1136,7 +1126,7 @@ static int test26(const void *unused G_GNUC_UNUSED) goto cleanup; } =20 - ret =3D checkoutput("test26", NULL); + ret =3D checkoutput("test26"); =20 cleanup: virCommandFree(cmd); @@ -1234,7 +1224,7 @@ static int test27(const void *unused G_GNUC_UNUSED) goto cleanup; } =20 - if (checkoutput("test27", NULL) < 0) + if (checkoutput("test27") < 0) goto cleanup; =20 ret =3D 0; --=20 2.26.2 From nobody Sat Apr 27 02:07:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595979692; cv=none; d=zohomail.com; s=zohoarc; b=I+6PkmDqvdEM0TR1ei3QJsp4rGUYkLwftUneSOVpAk9fwBDusip0m9yJlC/YJaGNnnOfjKbOz+nrkKzB/32vY8gzl8nNHEQOwOKFLoaYHkgKHP2xgagu+I7FsAHb+TlG5n78FK4ebV7rG2GyyCDePF4f/rOcJ5MtUfoDWB3TnBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595979692; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ujMrTeVLY5D1pTQXbsJ/pUA2fkZzETUh/HYzXZIJB7g=; b=LJYeXOl7Qnol7L1bqTYz188VOxGgWynjkMxWuXzP6tnYRXnOROl6OPZrGax8Kzl22K5EvttrwPV0T7gPa5YGcmkJOUw48nSfHMJLS60TYd1GLzjXHqenbuNbs6arWP1YJayHnW1aa9P3A2dNRjr8tu9DAvBQyzJzHRHhS2LORDM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1595979692521546.1237352051094; Tue, 28 Jul 2020 16:41:32 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-250-xYEYOxBAPgq-qKPfUis6-w-1; Tue, 28 Jul 2020 19:41:28 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7BDDA800688; Tue, 28 Jul 2020 23:41:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B4A510013C4; Tue, 28 Jul 2020 23:41:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2B4BF180599D; Tue, 28 Jul 2020 23:41:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06SNeuq7003864 for ; Tue, 28 Jul 2020 19:40:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id BAE7D8A160; Tue, 28 Jul 2020 23:40:56 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DC0079251 for ; Tue, 28 Jul 2020 23:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595979691; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ujMrTeVLY5D1pTQXbsJ/pUA2fkZzETUh/HYzXZIJB7g=; b=WXWReu0W6uotAB/KFqSIs66qnHWoXZHaz8zycCdRpm+YawRc99/UGU0KUEFs+G+t/pQxmG MUW7hkTYUGF2YfrscRjjdPkNKbAbg6kwdF0j6+6MjSbP1eGN/fO6hwBEhiz8jUwC8isLm0 3y4NJOPi74Y/SsH4qLhzWkpP/H93HLI= X-MC-Unique: xYEYOxBAPgq-qKPfUis6-w-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/5] tests: commandtest: use g_autofree Date: Wed, 29 Jul 2020 01:40:45 +0200 Message-Id: <7d375a013187adf13f2361e3519b72cab4192b7c.1595979625.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Laine Stump --- tests/commandtest.c | 76 ++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 50 deletions(-) diff --git a/tests/commandtest.c b/tests/commandtest.c index a18100a705..7c6c3ec75d 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -58,10 +58,10 @@ extern char **environ; static int checkoutput(const char *testname) { int ret =3D -1; - char *expectname =3D NULL; - char *expectlog =3D NULL; - char *actualname =3D NULL; - char *actuallog =3D NULL; + g_autofree char *expectname =3D NULL; + g_autofree char *expectlog =3D NULL; + g_autofree char *actualname =3D NULL; + g_autofree char *actuallog =3D NULL; =20 expectname =3D g_strdup_printf("%s/commanddata/%s.log", abs_srcdir, te= stname); actualname =3D g_strdup_printf("%s/commandhelper.log", abs_builddir); @@ -86,10 +86,6 @@ static int checkoutput(const char *testname) cleanup: if (actualname) unlink(actualname); - VIR_FREE(actuallog); - VIR_FREE(actualname); - VIR_FREE(expectlog); - VIR_FREE(expectname); return ret; } =20 @@ -247,7 +243,7 @@ static int test4(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNewArgList(abs_builddir "/commandhelpe= r", "--check-daemonize", NULL); - char *pidfile =3D virPidFileBuildPath(abs_builddir, "commandhelper"); + g_autofree char *pidfile =3D virPidFileBuildPath(abs_builddir, "comman= dhelper"); pid_t pid; int ret =3D -1; =20 @@ -275,7 +271,6 @@ static int test4(const void *unused G_GNUC_UNUSED) virCommandFree(cmd); if (pidfile) unlink(pidfile); - VIR_FREE(pidfile); return ret; } =20 @@ -484,7 +479,7 @@ static int test12(const void *unused G_GNUC_UNUSED) static int test13(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); - char *outactual =3D NULL; + g_autofree char *outactual =3D NULL; const char *outexpect =3D "BEGIN STDOUT\n" "Hello World\n" "END STDOUT\n"; @@ -512,7 +507,6 @@ static int test13(const void *unused G_GNUC_UNUSED) =20 cleanup: virCommandFree(cmd); - VIR_FREE(outactual); return ret; } =20 @@ -523,16 +517,16 @@ static int test13(const void *unused G_GNUC_UNUSED) static int test14(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); - char *outactual =3D NULL; + g_autofree char *outactual =3D NULL; const char *outexpect =3D "BEGIN STDOUT\n" "Hello World\n" "END STDOUT\n"; - char *erractual =3D NULL; + g_autofree char *erractual =3D NULL; const char *errexpect =3D "BEGIN STDERR\n" "Hello World\n" "END STDERR\n"; =20 - char *jointactual =3D NULL; + g_autofree char *jointactual =3D NULL; const char *jointexpect =3D "BEGIN STDOUT\n" "BEGIN STDERR\n" "Hello World\n" @@ -582,9 +576,6 @@ static int test14(const void *unused G_GNUC_UNUSED) =20 cleanup: virCommandFree(cmd); - VIR_FREE(outactual); - VIR_FREE(erractual); - VIR_FREE(jointactual); return ret; } =20 @@ -596,7 +587,7 @@ static int test14(const void *unused G_GNUC_UNUSED) static int test15(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); - char *cwd =3D NULL; + g_autofree char *cwd =3D NULL; int ret =3D -1; =20 cwd =3D g_strdup_printf("%s/commanddata", abs_srcdir); @@ -611,7 +602,6 @@ static int test15(const void *unused G_GNUC_UNUSED) ret =3D checkoutput("test15"); =20 cleanup: - VIR_FREE(cwd); virCommandFree(cmd); =20 return ret; @@ -623,7 +613,7 @@ static int test15(const void *unused G_GNUC_UNUSED) static int test16(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNew("true"); - char *outactual =3D NULL; + g_autofree char *outactual =3D NULL; const char *outexpect =3D "A=3DB C=3D'D E' true F 'G H'"; int ret =3D -1; int fd =3D -1; @@ -658,7 +648,6 @@ static int test16(const void *unused G_GNUC_UNUSED) cleanup: virCommandFree(cmd); VIR_FORCE_CLOSE(fd); - VIR_FREE(outactual); return ret; } =20 @@ -669,8 +658,8 @@ static int test17(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNew("true"); int ret =3D -1; - char *outbuf; - char *errbuf =3D NULL; + char *outbuf =3D NULL; + g_autofree char *errbuf =3D NULL; =20 virCommandSetOutputBuffer(cmd, &outbuf); if (outbuf !=3D NULL) { @@ -711,7 +700,6 @@ static int test17(const void *unused G_GNUC_UNUSED) cleanup: virCommandFree(cmd); VIR_FREE(outbuf); - VIR_FREE(errbuf); return ret; } =20 @@ -721,7 +709,7 @@ static int test17(const void *unused G_GNUC_UNUSED) static int test18(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNewArgList("sleep", "100", NULL); - char *pidfile =3D virPidFileBuildPath(abs_builddir, "commandhelper"); + g_autofree char *pidfile =3D virPidFileBuildPath(abs_builddir, "comman= dhelper"); pid_t pid; int ret =3D -1; =20 @@ -759,7 +747,6 @@ static int test18(const void *unused G_GNUC_UNUSED) virCommandFree(cmd); if (pidfile) unlink(pidfile); - VIR_FREE(pidfile); return ret; } =20 @@ -807,7 +794,7 @@ static int test20(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNewArgList(abs_builddir "/commandhelpe= r", "--close-stdin", NULL); - char *buf; + g_autofree char *buf =3D NULL; int ret =3D -1; =20 struct sigaction sig_action; @@ -829,7 +816,6 @@ static int test20(const void *unused G_GNUC_UNUSED) ret =3D checkoutput("test20"); cleanup: virCommandFree(cmd); - VIR_FREE(buf); return ret; } =20 @@ -850,7 +836,8 @@ static int test21(const void *unused G_GNUC_UNUSED) virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); int ret =3D -1; const char *wrbuf =3D "Hello world\n"; - char *outbuf =3D NULL, *errbuf =3D NULL; + g_autofree char *outbuf =3D NULL; + g_autofree char *errbuf =3D NULL; const char *outbufExpected =3D "BEGIN STDOUT\n" "Hello world\n" "END STDOUT\n"; @@ -886,8 +873,6 @@ static int test21(const void *unused G_GNUC_UNUSED) =20 ret =3D checkoutput("test21"); cleanup: - VIR_FREE(outbuf); - VIR_FREE(errbuf); virCommandFree(cmd); return ret; } @@ -1006,7 +991,7 @@ static int test25(const void *unused G_GNUC_UNUSED) int rv =3D 0; ssize_t tries =3D 100; pid_t pid; - gid_t *groups =3D NULL; + g_autofree gid_t *groups =3D NULL; int ngroups; virCommandPtr cmd =3D virCommandNew("some/nonexistent/binary"); =20 @@ -1068,7 +1053,6 @@ static int test25(const void *unused G_GNUC_UNUSED) cleanup: VIR_FORCE_CLOSE(pipeFD[0]); VIR_FORCE_CLOSE(pipeFD[1]); - VIR_FREE(groups); virCommandFree(cmd); return ret; } @@ -1080,7 +1064,7 @@ static int test25(const void *unused G_GNUC_UNUSED) static int test26(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNew("true"); - char *outactual =3D NULL; + g_autofree char *outactual =3D NULL; const char *outexpect =3D "A=3DB \\\n" "C=3D'D E' \\\n" @@ -1131,7 +1115,6 @@ static int test26(const void *unused G_GNUC_UNUSED) cleanup: virCommandFree(cmd); VIR_FORCE_CLOSE(fd); - VIR_FREE(outactual); return ret; } =20 @@ -1142,16 +1125,16 @@ static int test27(const void *unused G_GNUC_UNUSED) int pipe2[2]; int ret =3D -1; size_t buflen =3D 1024 * 128; - char *buffer0 =3D NULL; - char *buffer1 =3D NULL; - char *buffer2 =3D NULL; - char *outactual =3D NULL; - char *erractual =3D NULL; - char *outexpect =3D NULL; + g_autofree char *buffer0 =3D NULL; + g_autofree char *buffer1 =3D NULL; + g_autofree char *buffer2 =3D NULL; + g_autofree char *outactual =3D NULL; + g_autofree char *erractual =3D NULL; + g_autofree char *outexpect =3D NULL; # define TEST27_OUTEXPECT_TEMP "BEGIN STDOUT\n" \ "%s%s%s" \ "END STDOUT\n" - char *errexpect =3D NULL; + g_autofree char *errexpect =3D NULL; # define TEST27_ERREXPECT_TEMP "BEGIN STDERR\n" \ "%s%s%s" \ "END STDERR\n" @@ -1235,13 +1218,6 @@ static int test27(const void *unused G_GNUC_UNUSED) VIR_FORCE_CLOSE(pipe2[0]); VIR_FORCE_CLOSE(pipe1[1]); VIR_FORCE_CLOSE(pipe2[1]); - VIR_FREE(buffer0); - VIR_FREE(buffer1); - VIR_FREE(buffer2); - VIR_FREE(outactual); - VIR_FREE(erractual); - VIR_FREE(outexpect); - VIR_FREE(errexpect); =20 return ret; } --=20 2.26.2 From nobody Sat Apr 27 02:07:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595979671; cv=none; d=zohomail.com; s=zohoarc; b=B/YsUk9SDvSQO6HPkGrzoL6zyb7t3q4iaVfIuL3YbVD6NV8D/aB9AFuVaadFwcq7PlVn+86PxpGEJBsC0RyX05uP9a/un8oUXF58/lKpoJHcxeusgZtAe0GS+Cjc0xFYR3j886DMg1KXIcLl5J8o2SYYyHzfA3+ggVJtMxEfito= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595979671; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YANFmt70T5OJFGkqpfM2UPfpqmHU4ZcV2og8c01lEvw=; b=lbt66w4Yh2Iopsdq1bhdYT7iTFfIyGpuyQZd1mvMCmBYwyWjcAWgoQJYAigDnMEq/ufVUFIvfEmaIsIY0gfqyTIYM79al4VOG6l5sXsmijQkgBh0uNAO/mtdo3n1ArltEdKq2e2uMRrDIsq4/1Ps8oXLOjjsEOIk2s2lpeT5aNY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1595979671634819.3549941255194; Tue, 28 Jul 2020 16:41:11 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-195-Cc5m1kegMrmBVGLg3dixAA-1; Tue, 28 Jul 2020 19:41:08 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1730C107BEFA; Tue, 28 Jul 2020 23:41:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EDD9369328; Tue, 28 Jul 2020 23:40:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BCA58A359F; Tue, 28 Jul 2020 23:40:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06SNevU7003872 for ; Tue, 28 Jul 2020 19:40:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB0038A160; Tue, 28 Jul 2020 23:40:57 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3521679251 for ; Tue, 28 Jul 2020 23:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595979670; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=YANFmt70T5OJFGkqpfM2UPfpqmHU4ZcV2og8c01lEvw=; b=H79kBELHYWkp5Td9blRyk5+yRCK6ftsznt+LPJRyKqetsMpDS3VQEmP3VjFeHQ1fOM15Ln Z1uNUIMcbXURVWAdYIfxxJcaifEpygKiqtXcIYmclF+32RV6mM9qGaJuHLbmwURYm/v67F zx4Yu5Q1mCyIePElS+KU4+/F8h91mPA= X-MC-Unique: Cc5m1kegMrmBVGLg3dixAA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 3/5] tests: commandtest: use g_autoptr for virCommand Date: Wed, 29 Jul 2020 01:40:46 +0200 Message-Id: <9311042626bc296b255e507c03d655c9a9f14ac5.1595979625.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Except for a few cases where freeing it explicitly seems to be done on purpose. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Laine Stump --- tests/commandtest.c | 94 ++++++++++++--------------------------------- 1 file changed, 25 insertions(+), 69 deletions(-) diff --git a/tests/commandtest.c b/tests/commandtest.c index 7c6c3ec75d..a54e467b2b 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -96,7 +96,7 @@ static int checkoutput(const char *testname) */ static int test0(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd; + g_autoptr(virCommand) cmd =3D NULL; int ret =3D -1; =20 cmd =3D virCommandNew(abs_builddir "/commandhelper-doesnotexist"); @@ -110,7 +110,6 @@ static int test0(const void *unused G_GNUC_UNUSED) ret =3D 0; =20 cleanup: - virCommandFree(cmd); return ret; } =20 @@ -121,7 +120,7 @@ static int test0(const void *unused G_GNUC_UNUSED) */ static int test1(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd; + g_autoptr(virCommand) cmd =3D NULL; int ret =3D -1; int status; =20 @@ -139,7 +138,6 @@ static int test1(const void *unused G_GNUC_UNUSED) ret =3D 0; =20 cleanup: - virCommandFree(cmd); return ret; } =20 @@ -149,28 +147,22 @@ static int test1(const void *unused G_GNUC_UNUSED) */ static int test2(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); int ret; =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - virCommandFree(cmd); return -1; } =20 - if ((ret =3D checkoutput("test2")) !=3D 0) { - virCommandFree(cmd); + if ((ret =3D checkoutput("test2")) !=3D 0) return ret; - } =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - virCommandFree(cmd); return -1; } =20 - virCommandFree(cmd); - return checkoutput("test2"); } =20 @@ -180,7 +172,7 @@ static int test2(const void *unused G_GNUC_UNUSED) */ static int test3(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); int newfd1 =3D dup(STDERR_FILENO); int newfd2 =3D dup(STDERR_FILENO); int newfd3 =3D dup(STDERR_FILENO); @@ -226,7 +218,6 @@ static int test3(const void *unused G_GNUC_UNUSED) ret =3D checkoutput("test3"); =20 cleanup: - virCommandFree(cmd); /* coverity[double_close] */ VIR_FORCE_CLOSE(newfd1); VIR_FORCE_CLOSE(newfd2); @@ -241,8 +232,8 @@ static int test3(const void *unused G_GNUC_UNUSED) */ static int test4(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNewArgList(abs_builddir "/commandhelpe= r", - "--check-daemonize", NULL); + g_autoptr(virCommand) cmd =3D virCommandNewArgList(abs_builddir "/comm= andhelper", + "--check-daemonize", = NULL); g_autofree char *pidfile =3D virPidFileBuildPath(abs_builddir, "comman= dhelper"); pid_t pid; int ret =3D -1; @@ -268,7 +259,6 @@ static int test4(const void *unused G_GNUC_UNUSED) ret =3D checkoutput("test4"); =20 cleanup: - virCommandFree(cmd); if (pidfile) unlink(pidfile); return ret; @@ -281,18 +271,15 @@ static int test4(const void *unused G_GNUC_UNUSED) */ static int test5(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); =20 virCommandAddEnvPassCommon(cmd); =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - virCommandFree(cmd); return -1; } =20 - virCommandFree(cmd); - return checkoutput("test5"); } =20 @@ -303,19 +290,16 @@ static int test5(const void *unused G_GNUC_UNUSED) */ static int test6(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); =20 virCommandAddEnvPass(cmd, "DISPLAY"); virCommandAddEnvPass(cmd, "DOESNOTEXIST"); =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - virCommandFree(cmd); return -1; } =20 - virCommandFree(cmd); - return checkoutput("test6"); } =20 @@ -326,7 +310,7 @@ static int test6(const void *unused G_GNUC_UNUSED) */ static int test7(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); =20 virCommandAddEnvPassCommon(cmd); virCommandAddEnvPass(cmd, "DISPLAY"); @@ -334,12 +318,9 @@ static int test7(const void *unused G_GNUC_UNUSED) =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - virCommandFree(cmd); return -1; } =20 - virCommandFree(cmd); - return checkoutput("test7"); } =20 @@ -349,7 +330,7 @@ static int test7(const void *unused G_GNUC_UNUSED) */ static int test8(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); =20 virCommandAddEnvString(cmd, "USER=3Dbogus"); virCommandAddEnvString(cmd, "LANG=3DC"); @@ -358,12 +339,9 @@ static int test8(const void *unused G_GNUC_UNUSED) =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - virCommandFree(cmd); return -1; } =20 - virCommandFree(cmd); - return checkoutput("test8"); } =20 @@ -374,7 +352,7 @@ static int test8(const void *unused G_GNUC_UNUSED) */ static int test9(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); const char* const args[] =3D { "arg1", "arg2", NULL }; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; =20 @@ -388,18 +366,14 @@ static int test9(const void *unused G_GNUC_UNUSED) =20 if (virBufferUse(&buf)) { printf("Buffer not transferred\n"); - virCommandFree(cmd); return -1; } =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - virCommandFree(cmd); return -1; } =20 - virCommandFree(cmd); - return checkoutput("test9"); } =20 @@ -410,7 +384,7 @@ static int test9(const void *unused G_GNUC_UNUSED) */ static int test10(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); const char *const args[] =3D { "-version", "-log=3Dbar.log", NULL, }; @@ -419,12 +393,9 @@ static int test10(const void *unused G_GNUC_UNUSED) =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - virCommandFree(cmd); return -1; } =20 - virCommandFree(cmd); - return checkoutput("test10"); } =20 @@ -438,16 +409,13 @@ static int test11(const void *unused G_GNUC_UNUSED) abs_builddir "/commandhelper", "-version", "-log=3Dbar.log", NULL, }; - virCommandPtr cmd =3D virCommandNewArgs(args); + g_autoptr(virCommand) cmd =3D virCommandNewArgs(args); =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - virCommandFree(cmd); return -1; } =20 - virCommandFree(cmd); - return checkoutput("test11"); } =20 @@ -457,18 +425,15 @@ static int test11(const void *unused G_GNUC_UNUSED) */ static int test12(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); =20 virCommandSetInputBuffer(cmd, "Hello World\n"); =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - virCommandFree(cmd); return -1; } =20 - virCommandFree(cmd); - return checkoutput("test12"); } =20 @@ -586,7 +551,7 @@ static int test14(const void *unused G_GNUC_UNUSED) */ static int test15(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); g_autofree char *cwd =3D NULL; int ret =3D -1; =20 @@ -602,7 +567,6 @@ static int test15(const void *unused G_GNUC_UNUSED) ret =3D checkoutput("test15"); =20 cleanup: - virCommandFree(cmd); =20 return ret; } @@ -612,7 +576,7 @@ static int test15(const void *unused G_GNUC_UNUSED) */ static int test16(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew("true"); + g_autoptr(virCommand) cmd =3D virCommandNew("true"); g_autofree char *outactual =3D NULL; const char *outexpect =3D "A=3DB C=3D'D E' true F 'G H'"; int ret =3D -1; @@ -646,7 +610,6 @@ static int test16(const void *unused G_GNUC_UNUSED) ret =3D checkoutput("test16"); =20 cleanup: - virCommandFree(cmd); VIR_FORCE_CLOSE(fd); return ret; } @@ -656,7 +619,7 @@ static int test16(const void *unused G_GNUC_UNUSED) */ static int test17(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew("true"); + g_autoptr(virCommand) cmd =3D virCommandNew("true"); int ret =3D -1; char *outbuf =3D NULL; g_autofree char *errbuf =3D NULL; @@ -698,7 +661,6 @@ static int test17(const void *unused G_GNUC_UNUSED) =20 ret =3D 0; cleanup: - virCommandFree(cmd); VIR_FREE(outbuf); return ret; } @@ -755,7 +717,7 @@ static int test18(const void *unused G_GNUC_UNUSED) */ static int test19(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNewArgList("sleep", "100", NULL); + g_autoptr(virCommand) cmd =3D virCommandNewArgList("sleep", "100", NUL= L); pid_t pid; int ret =3D -1; =20 @@ -782,7 +744,6 @@ static int test19(const void *unused G_GNUC_UNUSED) ret =3D 0; =20 cleanup: - virCommandFree(cmd); return ret; } =20 @@ -792,8 +753,8 @@ static int test19(const void *unused G_GNUC_UNUSED) */ static int test20(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNewArgList(abs_builddir "/commandhelpe= r", - "--close-stdin", NULL); + g_autoptr(virCommand) cmd =3D virCommandNewArgList(abs_builddir "/comm= andhelper", + "--close-stdin", NULL= ); g_autofree char *buf =3D NULL; int ret =3D -1; =20 @@ -815,7 +776,6 @@ static int test20(const void *unused G_GNUC_UNUSED) =20 ret =3D checkoutput("test20"); cleanup: - virCommandFree(cmd); return ret; } =20 @@ -833,7 +793,7 @@ static const char *const newenv[] =3D { =20 static int test21(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); int ret =3D -1; const char *wrbuf =3D "Hello world\n"; g_autofree char *outbuf =3D NULL; @@ -873,7 +833,6 @@ static int test21(const void *unused G_GNUC_UNUSED) =20 ret =3D checkoutput("test21"); cleanup: - virCommandFree(cmd); return ret; } =20 @@ -993,7 +952,7 @@ static int test25(const void *unused G_GNUC_UNUSED) pid_t pid; g_autofree gid_t *groups =3D NULL; int ngroups; - virCommandPtr cmd =3D virCommandNew("some/nonexistent/binary"); + g_autoptr(virCommand) cmd =3D virCommandNew("some/nonexistent/binary"); =20 if (virPipeQuiet(pipeFD) < 0) { fprintf(stderr, "Unable to create pipe\n"); @@ -1053,7 +1012,6 @@ static int test25(const void *unused G_GNUC_UNUSED) cleanup: VIR_FORCE_CLOSE(pipeFD[0]); VIR_FORCE_CLOSE(pipeFD[1]); - virCommandFree(cmd); return ret; } =20 @@ -1063,7 +1021,7 @@ static int test25(const void *unused G_GNUC_UNUSED) */ static int test26(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew("true"); + g_autoptr(virCommand) cmd =3D virCommandNew("true"); g_autofree char *outactual =3D NULL; const char *outexpect =3D "A=3DB \\\n" @@ -1113,14 +1071,13 @@ static int test26(const void *unused G_GNUC_UNUSED) ret =3D checkoutput("test26"); =20 cleanup: - virCommandFree(cmd); VIR_FORCE_CLOSE(fd); return ret; } =20 static int test27(const void *unused G_GNUC_UNUSED) { - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); int pipe1[2]; int pipe2[2]; int ret =3D -1; @@ -1213,7 +1170,6 @@ static int test27(const void *unused G_GNUC_UNUSED) ret =3D 0; =20 cleanup: - virCommandFree(cmd); VIR_FORCE_CLOSE(pipe1[0]); VIR_FORCE_CLOSE(pipe2[0]); VIR_FORCE_CLOSE(pipe1[1]); --=20 2.26.2 From nobody Sat Apr 27 02:07:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595979674; cv=none; d=zohomail.com; s=zohoarc; b=C2XYc1fgEL/s5RMTyAWqfLmitSfZBkA4NI6CbSwYf5uFuJSldK64RFznMng/EEnbt4Sh6eXKoOS/FA3hXAhbyCijrPzQgskrvme6MXyesku1qcD/7r1rZ6thl9sBH6IUpgjjIBSpjoTopH7N81FWGSRfGmbHReXT8P0vP/zyNX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595979674; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=g2rGIQ59mnRApaNwLeTEwF9cBXS35kV9iPJplh/RI9U=; b=gVkX2AGDeBILpJ7YkOBIM+lm6O8s5LTo9ZdNqSnXpODmYVdn90pYyQbLVXPfy6vU/ZthASr3LTZqtNaAr1poHqiutwpdmWycHddHUrxiLrv5xkaASrfYPT7o5wOmF9lPMAd+mZBg7tLp8nSnGiPlNn2pH3Ecrq1ia7gINw5aOLU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1595979674432795.5563268951681; Tue, 28 Jul 2020 16:41:14 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-120-BXOZNkzBP7uSv0TBu0Is2A-1; Tue, 28 Jul 2020 19:41:09 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E7CB21DE4; Tue, 28 Jul 2020 23:40:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CC78E5D9F7; Tue, 28 Jul 2020 23:40:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 999461800FDE; Tue, 28 Jul 2020 23:40:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06SNexQw003879 for ; Tue, 28 Jul 2020 19:40:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 062218A168; Tue, 28 Jul 2020 23:40:59 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49DC779251 for ; Tue, 28 Jul 2020 23:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595979673; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=g2rGIQ59mnRApaNwLeTEwF9cBXS35kV9iPJplh/RI9U=; b=OfS6cxkXpTGcffTWSqJgRcbxV5hPxN7HO1icNaLKdyUL6jNYAMV7L7WfY7uu6ysugxrZAy /eHRV9N5zS+aGF7v9PLXL6toFbgOkSDQYeIpB4dpKOWiMusIshVZXqyKahuzMbp/Sb+7m+ kkbLgNd2sJsN2Z+g/zVawObuWkgHU0k= X-MC-Unique: BXOZNkzBP7uSv0TBu0Is2A-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/5] tests: commandtest: use VIR_AUTOCLOSE Date: Wed, 29 Jul 2020 01:40:47 +0200 Message-Id: <65382bcb14097f00d881244098c8c43d34584e46.1595979625.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Laine Stump --- tests/commandtest.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/commandtest.c b/tests/commandtest.c index a54e467b2b..b0bf6f379a 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -173,8 +173,8 @@ static int test2(const void *unused G_GNUC_UNUSED) static int test3(const void *unused G_GNUC_UNUSED) { g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); - int newfd1 =3D dup(STDERR_FILENO); - int newfd2 =3D dup(STDERR_FILENO); + VIR_AUTOCLOSE newfd1 =3D dup(STDERR_FILENO); + VIR_AUTOCLOSE newfd2 =3D dup(STDERR_FILENO); int newfd3 =3D dup(STDERR_FILENO); struct stat before, after; int ret =3D -1; @@ -218,9 +218,6 @@ static int test3(const void *unused G_GNUC_UNUSED) ret =3D checkoutput("test3"); =20 cleanup: - /* coverity[double_close] */ - VIR_FORCE_CLOSE(newfd1); - VIR_FORCE_CLOSE(newfd2); return ret; } =20 @@ -580,7 +577,7 @@ static int test16(const void *unused G_GNUC_UNUSED) g_autofree char *outactual =3D NULL; const char *outexpect =3D "A=3DB C=3D'D E' true F 'G H'"; int ret =3D -1; - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; =20 virCommandAddEnvPair(cmd, "A", "B"); virCommandAddEnvPair(cmd, "C", "D E"); @@ -610,7 +607,6 @@ static int test16(const void *unused G_GNUC_UNUSED) ret =3D checkoutput("test16"); =20 cleanup: - VIR_FORCE_CLOSE(fd); return ret; } =20 @@ -1039,7 +1035,7 @@ static int test26(const void *unused G_GNUC_UNUSED) "wallop"; =20 int ret =3D -1; - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; =20 virCommandAddEnvPair(cmd, "A", "B"); virCommandAddEnvPair(cmd, "C", "D E"); @@ -1071,7 +1067,6 @@ static int test26(const void *unused G_GNUC_UNUSED) ret =3D checkoutput("test26"); =20 cleanup: - VIR_FORCE_CLOSE(fd); return ret; } =20 --=20 2.26.2 From nobody Sat Apr 27 02:07:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595979675; cv=none; d=zohomail.com; s=zohoarc; b=fK6WjF04VK9RX6DBsiJZFAzSFd2Kba/qd2KF/KBJpl5xGxBnFV12MdYWgo8auuUDmUEr0K6olJqFsAaZxXM/Z17hO6qBADoA1B48hiuKQ9yavBHw9u9AwHaxtUgG6AqD0i0KUZGx0K4DErd5bsqY6TmXOLrn8Kk177tyS2w60HQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595979675; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rwpOrEIdcnJkSNCXhCUMWNlOBqXRVBX23BfgBJb6mCg=; b=mDZNRucTOaEU78ZZUfUFFv5f92L8mYJ4kC81xMInq/UgKy73R2cUZsm52cHfCzTWqXPoVXRLmqY5hb40WPLDbaKPwVXEUulXesCP47tw8GuPQjFNH3gQLAw2ANJVmqJ5y4hC0xll3NjHNfO8UfMu4QlWMIAd72JmvU1sWMOIJ3o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1595979675255168.05247491530133; Tue, 28 Jul 2020 16:41:15 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-432-AGGz-AbuPCy0eBky95N-sQ-1; Tue, 28 Jul 2020 19:41:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6DB9B107BEF6; Tue, 28 Jul 2020 23:41:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C788619C4; Tue, 28 Jul 2020 23:41:05 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1D5D01806B0D; Tue, 28 Jul 2020 23:41:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06SNf0vm003884 for ; Tue, 28 Jul 2020 19:41:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 24CF08A168; Tue, 28 Jul 2020 23:41:00 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 738D78A176 for ; Tue, 28 Jul 2020 23:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595979674; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rwpOrEIdcnJkSNCXhCUMWNlOBqXRVBX23BfgBJb6mCg=; b=g7Krb772XEYsNKCDP+tIT8oqfZ/LJtE9S7pv6auLK1czc24asdxM81ytBqd/1Dp3sKrQUz VwQiDAD7jSVsAXkXQbLb1J5dlbaMPQlUtSP9i1mBsjmj/u/bfcKmM3K5a1dPZb7cuDLl96 d+Ic2H29qrqSSJZYHSN4lz7zF1ZTO2w= X-MC-Unique: AGGz-AbuPCy0eBky95N-sQ-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 5/5] tests: commandtest: drop unnecessary labels Date: Wed, 29 Jul 2020 01:40:48 +0200 Message-Id: <4cd2610c0de48e6807c1bc15f200e217d9171a6d.1595979625.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Laine Stump --- tests/commandtest.c | 106 +++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 70 deletions(-) diff --git a/tests/commandtest.c b/tests/commandtest.c index b0bf6f379a..42225a8ef2 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -97,20 +97,16 @@ static int checkoutput(const char *testname) static int test0(const void *unused G_GNUC_UNUSED) { g_autoptr(virCommand) cmd =3D NULL; - int ret =3D -1; =20 cmd =3D virCommandNew(abs_builddir "/commandhelper-doesnotexist"); if (virCommandRun(cmd, NULL) =3D=3D 0) - goto cleanup; + return -1; =20 if (virGetLastErrorCode() =3D=3D VIR_ERR_OK) - goto cleanup; + return -1; =20 virResetLastError(); - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 /* @@ -121,24 +117,21 @@ static int test0(const void *unused G_GNUC_UNUSED) static int test1(const void *unused G_GNUC_UNUSED) { g_autoptr(virCommand) cmd =3D NULL; - int ret =3D -1; int status; =20 cmd =3D virCommandNew(abs_builddir "/commandhelper-doesnotexist"); if (virCommandRun(cmd, &status) < 0) - goto cleanup; + return -1; if (status !=3D EXIT_ENOENT) - goto cleanup; + return -1; =20 virCommandRawStatus(cmd); if (virCommandRun(cmd, &status) < 0) - goto cleanup; + return -1; if (!WIFEXITED(status) || WEXITSTATUS(status) !=3D EXIT_ENOENT) - goto cleanup; - ret =3D 0; + return -1; =20 - cleanup: - return ret; + return 0; } =20 /* @@ -177,11 +170,10 @@ static int test3(const void *unused G_GNUC_UNUSED) VIR_AUTOCLOSE newfd2 =3D dup(STDERR_FILENO); int newfd3 =3D dup(STDERR_FILENO); struct stat before, after; - int ret =3D -1; =20 if (fstat(newfd3, &before) < 0) { perror("fstat"); - goto cleanup; + return -1; } virCommandPassFD(cmd, newfd1, 0); virCommandPassFD(cmd, newfd3, @@ -189,13 +181,13 @@ static int test3(const void *unused G_GNUC_UNUSED) =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - goto cleanup; + return -1; } =20 if (fcntl(newfd1, F_GETFL) < 0 || fcntl(newfd2, F_GETFL) < 0) { puts("fds 1/2 were not open"); - goto cleanup; + return -1; } =20 /* We expect newfd3 to be closed, but the @@ -211,14 +203,11 @@ static int test3(const void *unused G_GNUC_UNUSED) before.st_dev =3D=3D after.st_dev && before.st_mode =3D=3D after.st_mode) { puts("fd 3 should not be open"); - goto cleanup; + return -1; } } =20 - ret =3D checkoutput("test3"); - - cleanup: - return ret; + return checkoutput("test3"); } =20 =20 @@ -550,7 +539,6 @@ static int test15(const void *unused G_GNUC_UNUSED) { g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); g_autofree char *cwd =3D NULL; - int ret =3D -1; =20 cwd =3D g_strdup_printf("%s/commanddata", abs_srcdir); virCommandSetWorkingDirectory(cmd, cwd); @@ -558,14 +546,10 @@ static int test15(const void *unused G_GNUC_UNUSED) =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - goto cleanup; + return -1; } =20 - ret =3D checkoutput("test15"); - - cleanup: - - return ret; + return checkoutput("test15"); } =20 /* @@ -576,7 +560,6 @@ static int test16(const void *unused G_GNUC_UNUSED) g_autoptr(virCommand) cmd =3D virCommandNew("true"); g_autofree char *outactual =3D NULL; const char *outexpect =3D "A=3DB C=3D'D E' true F 'G H'"; - int ret =3D -1; VIR_AUTOCLOSE fd =3D -1; =20 virCommandAddEnvPair(cmd, "A", "B"); @@ -586,28 +569,25 @@ static int test16(const void *unused G_GNUC_UNUSED) =20 if ((outactual =3D virCommandToString(cmd, false)) =3D=3D NULL) { printf("Cannot convert to string: %s\n", virGetLastErrorMessage()); - goto cleanup; + return -1; } if ((fd =3D open(abs_builddir "/commandhelper.log", O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0) { printf("Cannot open log file: %s\n", g_strerror(errno)); - goto cleanup; + return -1; } virCommandWriteArgLog(cmd, fd); if (VIR_CLOSE(fd) < 0) { printf("Cannot close log file: %s\n", g_strerror(errno)); - goto cleanup; + return -1; } =20 if (STRNEQ(outactual, outexpect)) { virTestDifference(stderr, outexpect, outactual); - goto cleanup; + return -1; } =20 - ret =3D checkoutput("test16"); - - cleanup: - return ret; + return checkoutput("test16"); } =20 /* @@ -715,32 +695,28 @@ static int test19(const void *unused G_GNUC_UNUSED) { g_autoptr(virCommand) cmd =3D virCommandNewArgList("sleep", "100", NUL= L); pid_t pid; - int ret =3D -1; =20 alarm(5); if (virCommandRunAsync(cmd, &pid) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - goto cleanup; + return -1; } =20 if (kill(pid, 0) !=3D 0) { printf("Child should still be running"); - goto cleanup; + return -1; } =20 virCommandAbort(cmd); =20 if (kill(pid, 0) =3D=3D 0) { printf("Child should be aborted"); - goto cleanup; + return -1; } =20 alarm(0); =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 /* @@ -752,7 +728,6 @@ static int test20(const void *unused G_GNUC_UNUSED) g_autoptr(virCommand) cmd =3D virCommandNewArgList(abs_builddir "/comm= andhelper", "--close-stdin", NULL= ); g_autofree char *buf =3D NULL; - int ret =3D -1; =20 struct sigaction sig_action; =20 @@ -767,12 +742,10 @@ static int test20(const void *unused G_GNUC_UNUSED) =20 if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - goto cleanup; + return -1; } =20 - ret =3D checkoutput("test20"); - cleanup: - return ret; + return checkoutput("test20"); } =20 static const char *const newenv[] =3D { @@ -790,7 +763,6 @@ static const char *const newenv[] =3D { static int test21(const void *unused G_GNUC_UNUSED) { g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); - int ret =3D -1; const char *wrbuf =3D "Hello world\n"; g_autofree char *outbuf =3D NULL; g_autofree char *errbuf =3D NULL; @@ -808,28 +780,26 @@ static int test21(const void *unused G_GNUC_UNUSED) =20 if (virCommandRunAsync(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - goto cleanup; + return -1; } =20 if (virCommandWait(cmd, NULL) < 0) - goto cleanup; + return -1; =20 if (virTestGetVerbose()) printf("STDOUT:%s\nSTDERR:%s\n", NULLSTR(outbuf), NULLSTR(errbuf)); =20 if (STRNEQ_NULLABLE(outbuf, outbufExpected)) { virTestDifference(stderr, outbufExpected, outbuf); - goto cleanup; + return -1; } =20 if (STRNEQ_NULLABLE(errbuf, errbufExpected)) { virTestDifference(stderr, errbufExpected, errbuf); - goto cleanup; + return -1; } =20 - ret =3D checkoutput("test21"); - cleanup: - return ret; + return checkoutput("test21"); } =20 static int @@ -1034,7 +1004,6 @@ static int test26(const void *unused G_GNUC_UNUSED) "bang \\\n" "wallop"; =20 - int ret =3D -1; VIR_AUTOCLOSE fd =3D -1; =20 virCommandAddEnvPair(cmd, "A", "B"); @@ -1046,28 +1015,25 @@ static int test26(const void *unused G_GNUC_UNUSED) =20 if ((outactual =3D virCommandToString(cmd, true)) =3D=3D NULL) { printf("Cannot convert to string: %s\n", virGetLastErrorMessage()); - goto cleanup; + return -1; } if ((fd =3D open(abs_builddir "/commandhelper.log", O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0) { printf("Cannot open log file: %s\n", g_strerror(errno)); - goto cleanup; + return -1; } virCommandWriteArgLog(cmd, fd); if (VIR_CLOSE(fd) < 0) { printf("Cannot close log file: %s\n", g_strerror(errno)); - goto cleanup; + return -1; } =20 if (STRNEQ(outactual, outexpect)) { virTestDifference(stderr, outexpect, outactual); - goto cleanup; + return -1; } =20 - ret =3D checkoutput("test26"); - - cleanup: - return ret; + return checkoutput("test26"); } =20 static int test27(const void *unused G_GNUC_UNUSED) --=20 2.26.2